I'm trying to configure a Linux server (NGINX) to allow HTTP requests through port 80 and it just doesn't seem to budge.
When I run curl localhost:80 from within the server, I get the correct response. But as soon as I change localhost to the public IP address, it gives the following error: curl: (7) Failed to connect to <ip> port 80: No route to host. Here are the things I've tried:
ping <ip>workssudo ufw disableto temporarily disable the server firewall (I also added80/tcpto my allowedufwlist. Output ofsudo ufw status:
Status: active To Action From -- ------ ---- Nginx Full ALLOW Anywhere OpenSSH ALLOW Anywhere 80 ALLOW Anywhere 443 ALLOW Anywhere 80/tcp ALLOW Anywhere Nginx Full (v6) ALLOW Anywhere (v6) OpenSSH (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6) 443 (v6) ALLOW Anywhere (v6) 80/tcp (v6) ALLOW Anywhere (v6) netstat -ltnshows port 80 being listened to:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN If it helps, here is my NGINX configuration (and yes, NGINX is live XD):
upstream django { server 127.0.0.1:5000; # server unix:///home/ubuntu/app/lyricschords/lyricschords.sock; #server unix:///home/ubuntu/lyrics-chords/lyrics-chords.sock; } server { listen 80; server_name 127.0.0.1 localhost <ip>; location /media/ { alias /home/ubuntu/app/lyricschords/media/; } location /static/ { alias /home/ubuntu/app/lyricschords/static/; } location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; } } I also have Django running on port 5000 via uWSGI.
Any help would be greatly appreciated!
42 Answers
For anyone using Oracle, this post ended up solving things: . Turned out just to be a firewall issue
If localhost:80 works but the external IP does not, then the webserver is at least listening on port 80, but either it is listening on localhost only or it is firewalled on the public IP.
You can use tools like netstat -lt or ss -lt to get a list of ports being listend to, and look for *:http or [::]:http which indicates listening on the wildcard ip address. If instead you see 127.0.0.1:http then it is only listening on the local ip address. Or you can check your web server configuration.