I try to curl/access a test website hosted on my Nginx web server (on Ubuntu Server).
My problem is : If I curl my private IP (192.X.X.X), it works fine. If I curl my public IP (X.X.X.X) when connected to my LAN (the same network as my web server), it works too. But when I curl my public IP (X.X.X.X) from another network, I get an empty response :
curl -L http://X.X.X.X:80/index.html --verbose #or curl -L http://X.X.X.X --verbose
* Trying X.X.X.X:80...
* Connected to X.X.X.X (X.X.X.X) port 80 (#0)
> GET /index.html HTTP/1.1
> Host: X.X.X.X
> User-Agent: curl/7.78.0
> Accept: */*
>
* Empty reply from server
* Closing connection 0
curl: (52) Empty reply from server
I get the same answer when I try to pass a Host to the headers with curl --verbose --header 'Host: example.com' 'http://X.X.X.X'
My file /etc/nginx/nginx.conf
is as follow :
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
gzip on;
server {
listen *:80;
listen [::]:80;
#server_name _;
server_name example.com;
root /var/www/example.com;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}
}
I try to change the file /etc/hosts
:
127.0.0.1 localhost
127.0.1.1 nginx01
127.0.1.1 example.com
X.X.X.X example.com #public IP
My firewall is disabled :
systemctl status ufw
ā ufw.service - Uncomplicated firewall
Loaded: loaded (/usr/lib/systemd/system/ufw.service; enabled; preset: enabled)
Active: inactive (dead) since Mon 2025-03-24 11:36:15 UTC; 1min 56s ago
The output from netstat
is :
sudo netstat -tulpn | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1576/nginx: master
tcp6 0 0 :::80 :::* LISTEN 1576/nginx: master
In the file /var/log/nginx/access.log
, I can see the request from my network but nothing from external network :
tail -5 /var/log/nginx/access.log
192.168.1.1 - - [24/Mar/2025:11:42:46 +0000] "GET /index.html HTTP/1.1" 200 173 "-" "curl/8.5.0"
192.168.1.1 - - [24/Mar/2025:11:51:56 +0000] "GET /index.html HTTP/1.1" 200 173 "-" "curl/8.5.0"
192.168.1.1 - - [24/Mar/2025:11:53:36 +0000] "GET /index.html HTTP/1.1" 200 173 "-" "curl/8.5.0"
192.168.1.1 - - [24/Mar/2025:11:53:43 +0000] "GET / HTTP/1.1" 200 173 "-" "curl/8.5.0"
192.168.1.1 - - [24/Mar/2025:11:53:54 +0000] "GET / HTTP/1.1" 200 173 "-" "curl/8.5.0"
I am completely stuck (I have read and tried all the answers to similar questions). Thanks for your help !
My ISP blocks traffic on specific ports (including port 80). By changing the port, my site is accessible from the outside!