0

I have got a Google Cloud VM with Firewall configured to allow tcp:8080 and tcp:80

Firewall screen

I've also configured ufw:

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere                  
8080                       ALLOW       Anywhere                       
Nginx HTTP (v6)            ALLOW       Anywhere (v6)             
8080 (v6)                  ALLOW       Anywhere (v6) 

And checked that port 8080 is open:

> sudo nmap -sT -O localhost
PORT     STATE SERVICE
80/tcp   open  http
8080/tcp open  http-proxy

Nginx config:

events {
  worker_connections 1024;
}

http {
  server {
    listen 8080;
    location /some_endpoint {
      proxy_pass http://localhost:<port>/<route>;
  }
}

Then I'm running an nginx on host (without container, just on the VM itself) and in this configutarion I cannot access my machine from the internet - "The connection has timed out", no errors in error.log and nothing in access.log

But! If I'm running same version of nginx with the same config file in the docker in the same VM, then everything is OK and nginx can be reached through the internet.

I'm really struggling to understand what am I doing wrong and how to properly run nginx on a VM itself.

Edit: additional info:

Output of sudo netstat -tulpn | grep LISTEN:

tcp        0      0 127.0.0.1:8099          0.0.0.0:*               LISTEN      6149/traefik                
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      14761/nginx: master 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      542/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      797/sshd: /usr/sbin   
    

Output of curl -v <url>:

*   Trying <URL>...
* connect to <URL> port 8080 failed: Timed out
* Failed to connect to <URL> port 8080 after 21045 ms: Timed out
* Closing connection 0
curl: (28) Failed to connect to <URL> port 8080 after 21045 ms: Timed out
7
  • Is Docker running in the VM or someplace else? What error do you get? Edit your question with problem details. Commented May 23, 2022 at 19:58
  • Yes, Docker is running on the same machine. The error while running on VM and not in the container is "The connection has timed out" Commented May 23, 2022 at 20:02
  • Show the Nginx configuration. Is it listening on localhost (127.0.0.1) or 0.0.0.0? Commented May 23, 2022 at 20:35
  • Added to main post Commented May 24, 2022 at 3:54
  • Use the curl command and post the output: curl -v your_url Commented May 24, 2022 at 8:04

1 Answer 1

0

Nginx is listening on localhost:8080. Localhost is no accessible from outside the machine.

Change the listen directive to:

listen *:8080;
6
  • I've tried that, but it lead to no difference, maybe after config change I should do something other than sudo systemctl reload nginx? Commented May 24, 2022 at 6:35
  • @SashaKorekov - you must restart Nginx: sudo systemctl restart nginx Commented May 24, 2022 at 6:42
  • Tried that, made no difference (also made a config check via nginx -T) Commented May 24, 2022 at 6:54
  • Put the output from this command in your question: sudo netstat -tulpn | grep LISTEN Commented May 24, 2022 at 6:56
  • 1
    @SashaKorekov - Please move those details into your question. They are a mess inside comments. Commented May 24, 2022 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .