Report this

What is the reason for this report?

Nginx, and Gunicorn on CentOS 7 dont work

Posted on June 14, 2018

I followed the tutorial and could not publish my application with django. I performed all the procedures described in the tutorial including let SELINUX permissive. Is there any more procedure I can do to make it work correctly?

Work !!!
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
[root@nxpython ~]# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nxpython ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Qui 2018-06-14 06:44:03 UTC; 4s ago
  Process: 1394 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1391 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1390 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1396 (nginx)
   CGroup: /system.slice/nginx.service
           ├─1396 nginx: master process /usr/sbin/nginx
           └─1397 nginx: worker process

thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

Based on the information you provided, it seems that Nginx and Gunicorn are running correctly. However, you might have an issue with the Nginx configuration for your Django application.

Here’s a sample Nginx configuration for a Django application with Gunicorn:

upstream myproject {
    server 127.0.0.1:8000;
}

server {
    listen 80;
    server_name mydomain.com;  # Replace with your domain name

    location / {
        proxy_pass http://myproject;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /static/ {
        alias /path/to/your/static/files/;  # Replace with the path to your static files
    }

    location /media/ {
        alias /path/to/your/media/files/;  # Replace with the path to your media files
    }

    error_page 502 /502.html;
}

Replace mydomain.com with your actual domain name, and /path/to/your/static/files/ and /path/to/your/media/files/ with the correct paths to your Django project’s static and media files.

  1. sudo nginx -t
  2. sudo systemctl restart nginx

Make sure Gunicorn is running using the command you provided:

  1. gunicorn --bind 127.0.0.1:8000 myproject.wsgi:application

Now your Django application should be accessible via your domain name.

For a more production-ready setup, you should also configure Gunicorn as a systemd service, so it starts automatically on system boot and restarts if it crashes.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.