Nginx running ip access in browser work but dns timeout - nginx

I'm running into an issue that I can't solve myself...
I'm running a Debian 10 server with nginx freshly installed on it.
IPV4: 149.56.45.129, DNS: yocha.app
Result of hostnamectl:
Static hostname: yocha.app
Icon name: computer-vm
Chassis: vm
Machine ID: d72735cff36a41f0a5326f0bb7eb1778
Boot ID: 72dd9022a4894eeea82bc74480543823
Virtualization: kvm
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-13-cloud-amd64
Architecture: x86-64
My /etc/hosts:
127.0.0.1 localhost
149.56.45.129 yocha.app
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
My nginx sites-avaible/default:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name yocha.app;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
When I access my ip address in the browser, I do get the nginx welcome message which is good I guess.
BUT when I try to access the dns the request timed out with no return...
I can log with ssh on my dns, I can ping it with no problems I even can curl it but when It comes to access it on a Browser, nothing happens.
curl -I http://149.56.45.129:80
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Thu, 21 Jan 2021 13:40:16 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 21 Jan 2021 13:05:20 GMT
Connection: keep-alive
ETag: "60097c10-264"
Accept-Ranges: bytes
me#yocha:~$ curl -I http://yocha.app:80
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Thu, 21 Jan 2021 13:40:25 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 21 Jan 2021 13:05:20 GMT
Connection: keep-alive
ETag: "60097c10-264"
Accept-Ranges: bytes
http://yocha.app on a browser
Anyone having a clue for me ?
Thanks a lot in advance !

Your site is redirecting to https:
$ curl -v http://yocha.app
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.14.2
< Date: Fri, 29 Jan 2021 20:21:46 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< Location: https://yocha.app/
and port 443 is not open or it's blocked:
$ telnet yocha.app 443
Trying 149.56.45.129...
telnet: Unable to connect to remote host: Connection timed out
DNS is fine: check your firewall or make sure nginx is propertly configured to listen on port 443 and to serve an ssl certificate.

Related

ERR_TOO_MANY_REDIRECTS with nginx and SSL on a VPS (Linux Ubuntu)

I tried to follow the blog post How to setup secure subdomains using nginx and certbot on a VPS, but get the error "ERR_TOO_MANY_REDIRECTS" when I try to connect to my website on my Browser.
I also tried deleting the Cache and all other data.
The only solutions I found are about Cloudflare or other big providers, but I am using a VPS from IONOS.
My config file looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name fleeser.com www.fleeser.com;
return 301 https://fleeser.com$request_uri;
}
server {
listen 443 ssl;
root /var/www/fleeser.com;
index index.html index.htm;
server_name www.fleeser.com;
ssl_certificate /etc/letsencrypt/live/fleeser.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/fleeser.com/privkey.pem;
return 301 https://fleeser.com$request_uri;
}
server {
listen 443 ssl;
root /var/www/fleeser.com;
index index.html index.htm;
ssl_certificate /etc/letsencrypt/live/fleeser.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/fleeser.com/privkey.pem;
}
My subdomain config for blog.fleeser.com looks the exact same, only change I made was removing default_server from the file and adding blog. infront of every fleeser.com.
Output of wget -S https://fleeser.com:
--2022-02-27 16:06:10-- https://fleeser.com/
Resolving fleeser.com (fleeser.com)... 82.165.108.165
Connecting to fleeser.com (fleeser.com)|82.165.108.165|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 27 Feb 2022 16:06:10 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://fleeser.com/
Location: https://fleeser.com/ [following]
--2022-02-27 16:06:10-- https://fleeser.com/
Reusing existing connection to fleeser.com:443.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 27 Feb 2022 16:06:10 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://fleeser.com/
Location: https://fleeser.com/ [following]
--2022-02-27 16:06:10-- https://fleeser.com/
Reusing existing connection to fleeser.com:443.
...
20 redirections exceeded.

problem with telnet HTTP/1.1 400 Bad Request

I was trying to do this:
Telnet into a Web server and send a multiline request message. Include in the request message the If-modified-since: header line to force a response message with the 304 Not Modified status code.
so I did steps below
telnet example.com 80
and then
GET /index.html HTTP/1.1
Host: example.com
and two enter.
and I got some information.
I added
If-modified-since: Thu, 17 Oct 2019 06:18:26 GMT
but still no 304 not modified.
this is what I get after GEt and Host
and
HTTP/1.0 501 Not Implemented
Content-Type: text/html
Content-Length: 357
Connection: close
Date: Fri, 30 Apr 2021 16:10:33 GMT
Server: ECSF (dcb/7F80)
HTTP/1.1 needs the Host header.
Your request should be:
GET /index.html HTTP/1.1
Host: hostname.tld
Edit
So if you are connecting to example.com:
GET /index.html HTTP/1.1
Host: example.com

NGINX reverse proxy to https upstream

trying to set up Nginx reverse proxy in front of AWS Elastic Load Balancer with TSL enabled on it.
The configuration I've tried:
events {}
http {
upstream pricing {
server pricing-api.my-awselb.com:443;
}
server {
listen 80;
server_name localhost;
location /pricing {
proxy_pass https://pricing;
}
}
}
Now when I run Nginx in docker locally on port 8080 when I try test it I get 404
> http http://localhost:8080/pricing
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Length: 0
Date: Wed, 21 Oct 2020 21:47:56 GMT
Server: nginx/1.19.3
upstream itself is accessible from my local machine:
> http https://pricing-api.my-awselb.com
HTTP/1.1 302 Found
Connection: keep-alive
Content-Length: 0
Date: Wed, 21 Oct 2020 21:54:36 GMT
Location: /swagger
Server: Kestrel
Whats wrong with my Nginx configuration?

Kong behind nginx reverse proxy

I use Kong as my API Gateway, running in a Docker container. By executing the following command from docker host, i get the correct answer.
root#prod-s-swarm01:~# curl -i -X GET --url http://prod-s-swarm:8000 --header 'Host: example.com' --header 'apikey: auth-key-maks'
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Thu, 24 Oct 2019 11:16:10 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
X-RateLimit-Remaining-hour: 4
X-RateLimit-Limit-second: 2
X-RateLimit-Remaining-second: 1
X-RateLimit-Limit-hour: 5
X-Kong-Upstream-Latency: 25
X-Kong-Proxy-Latency: 139
Via: kong/1.3.0
<!DOCTYPE html>
<html lang="ru">
<head>
.......
But, this request over my nginx proxy return not correct answer:
root#prod-s-swarm01:~# curl -i -X GET --url https://kong.myserver.com --header 'Host: example.com' --header 'apikey: auth-key-maks'
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Oct 2019 11:14:33 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 97
Connection: keep-alive
X-Powered-By: Express
ETag: W/"61-Mn0BCF+92vC7dF087oyDAFsiE"
{"Status":"ERROR","Error":"Bad authorize","ErrorDesc":"Не верная авторизация"}
My nginx proxy config:
server {
listen 443 ssl;
server_name kong.myserver.com;
ssl_certificate /etc/letsencrypt/live/appgw/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/appgw/privkey.pem;
location / {
proxy_pass http://prod-s-swarm:8000;
proxy_set_header Host $host;
}
}
I tried to use, $http_host - this also not work.
Another Host's fall into in default_server on nginx. Or in server_name is necessary write all domains in kong api.

HTTP headers return 404 on non-www URL?

I'm doing PHP get_headers() on an mp3 file on my server and receive HTTP 404 when using the non-www address and HTTP 200 when using www.
I can access the file from either address in the browser, so why the 404? Can I fix this somehow with .htaccess?
1) WordPress is configured to use the non-www address (example.com)
2) The files are in the wp-content/uploads area of the WordPress install
3) The www subdomain has a DNS CNAME pointing to the non-www domain (www.example.com -> example.com)
Headers for: http://lhcsj.org/wp-content/uploads/2012/05/2012-5-6-sj.mp3
HTTP/1.1 404 Not Found
Date: Tue, 08 May 2012 21:11:43 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 314
Connection: close
Content-Type: text/html; charset=iso-8859-1
Headers for: http://www.lhcsj.org/wp-content/uploads/2012/05/2012-5-6-sj.mp3
HTTP/1.1 200 OK
Date: Tue, 08 May 2012 21:08:05 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Mon, 07 May 2012 17:19:47 GMT
ETag: "9c52430-e3626f-7a1332c0"
Accept-Ranges: bytes
Content-Length: 14901871
Connection: close
Content-Type: audio/mpeg
The fact that www.example.com and example.com point to the same IP address via a DNS CNAME entry doesn't mean that the server is configured to serve both. This server could be configured to handle a multitude of HTTP hosts and the default might not be www.example.com but something else. It would in fact be unsurprising behaviour that it returns a 404 status for a host for which it's not configured (not even a default host).
Check that there is a VirtualHost entry in your Apache Httpd configuration for each of www.example.com and example.com. The fact that Wordpress is configured for a particular host only comes into play after having passed that step.

Resources