sunwarr10r
sunwarr10r

Reputation: 4787

Nginx (proxy_pass) + Gunicorn can’t be reached

I want to run django with gunicorn and nginx as a proxy server on a remote Ubuntu VPS.

The site works with djangos dev server:

python manage.py runserver 0.0.0.0:8000

The site works with gunicorns server (even static files don't work):

gunicorn my_project.wsgi --bind 0.0.0.0:8000

But with nginx on top I get the following error:

This site can’t be reached ... refused to connect. ERR_CONNECTION_REFUSED

Also both nginx log files error.log & access.log are empty.

Here is how I configured nginx:

server {
        listen 80;

        server_name my_ip_address;

        location / {
            proxy_pass http://127.0.0.1:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
        }
} 

In this case gunicorn runs with --bind 127.0.0.1:8001 of course.

Status check (service nginx status) returns:

● nginx.service - A high performance web server and a reverse proxy server
Active: active (running) since Fri 2019-09-20 07:41:00 UTC; 1min 19s ago
Starting A high performance web server and a reverse proxy server...
nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Started A high performance web server and a reverse proxy server.

Upvotes: 0

Views: 4305

Answers (1)

Daniel Hepper
Daniel Hepper

Reputation: 29977

First, check your configuration with nginx -t. The configuration you posted is not valid as a standalone config file, but I assume you are using the common nginx config structure of having a main nginx.conf and sites-available and sites-enabled directories.

If it does not complain, introduce an error, e.g. by removing a closing bracket, and try again. If it still doesn't complain, your configuration is not being picked up by nginx.

In this case, check if you created a correct symlink from sites-enabled/your_config to sites-available/your_config.

If that all seems correct:

  • check if nginx is actually running: ps aux | grep nginx
  • check if nginx is listening to port 80: netstat -tulpen | grep ":80"
  • check firewall rules

Upvotes: 2

Related Questions