Randy Tang
Randy Tang

Reputation: 4363

Nginx: listen to 8080 for proxy_pass, but not 80

I can't seem to make this nginx config work on port 80. I tried to deploy a django application using nginx and gunicorn. I used the following command to run gunicorn:

gunicorn myproj.wsgi:application --bind=127.0.0.1:8001 --workers=9

The following is the nginx config file /etc/nginx/sites-enabled/myproj:

server {
    listen 8080;
    location / {
       proxy_pass http://127.0.0.1:8001;
    }
    location /static/ {
       root /webapps/myproj/;
    }
}

Everything works fine except that I have to enter http://localhost:8080/ locally or http://xxx.xxx.xxx:8080/ for the application to run correctly. Without the port number 8080, the page would not be found.

However, if I change the listen 8080; into listen 80; in the config file (myproj) and enter http://localhost/ locally or http://xxx.xxx.xxx/ remotely, the page only shows the welcome message from nginx. Nginx seems not forwarding the request to my application. What was the problem?

Upvotes: 0

Views: 1206

Answers (2)

Dmitry MiksIr
Dmitry MiksIr

Reputation: 4455

Probably because other server with listen 80; exists.

You can remove other server defenition. Or change listen 80; to listen 80 default_server;. Or use server_name directive for name-based process.

Read this about how nginx decides which server should process the request: http://nginx.org/en/docs/http/request_processing.html

Upvotes: 0

catavaran
catavaran

Reputation: 45595

You need to specify domain or IP to bind to.

listen XXX.XXX.XXX:80;

Upvotes: 2

Related Questions