How can I check if gunicorn works and communicates with nginx?

I am using my first attempt to use django + gunicorn + nginx.

  • curl -XGET http://127.0.0.0.1:8000 working for me ( curl -XGET http://127.0.0.0.1:8000 works fine if I start the development server).
  • My nginx works for static content (for example, I can get http://example.com/static/my_pic.png in my browser).
  • I am not getting any wsgi content from my site and I have not been able to find a good troubleshooting guide (this just works for everyone!). I start shooting with the help of a supervisor who reports that it really works:

(in shell :)

 supervisorctl status my_app my_app RUNNING pid 1002, uptime 0:29:51 

Here's the script template I used to run it:

 #!/bin/bash #script variables NAME="gunicorn_myapp" # Name of process DJANGODIR=/webapps/www/my_project # Django project directory SOCKFILE=/webapps/www/run/gunicorn.sock # communicte using this socket USER=app_user # the user to run as GROUP=webapps # the group to run as NUM_WORKERS=3 DJANGO_SETTINGS_MODULE=my_project.settings # settings file DJANGO_WSGI_MODULE=my_project.wsgi # WSGI module name # Activate the virtual environment cd $DJANGODIR source ../bin/activate export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE export PYTHONPATH=$DJANGODIR:$PYTHONPATH # Create the run directory if it doesn't exist RUNDIR=$(dirname $SOCKFILE) test -d $RUNDIR || mkdir -p $RUNDIR exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \ --name $NAME \ --workers $NUM_WORKERS \ --user=$USER --group=$GROUP \ --bind=unix:$SOCKFILE 

Here's the configured nginx configuration file:

 upstream my_server { server unix:/webapps/www/run/gunicorn.sock fail_timeout=10s; } server { listen 80; server_name www.example.com; return 301 $scheme://example.com$request_uri; } server { listen 80; server_name example.com; client_max_body_size 4G; access_log /webapps/www/logs/nginx-access.log; error_log /webapps/www/logs/nginx-error.log; location /favicon.ico { access_log off; log_not_found off; } location /static/ { autoindex on; alias /webapps/www/my_project/my_app/static/; } location /media/ { autoindex on; alias /webapps/www/my_project/my_app/media/; } location / { proxy_pass http://my_server; proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://example.com; break; } } location /robots.txt { alias /webapps/www/my_project/my_app/static/robots.txt ; } # Error pages error_page 500 502 503 504 /500.html; location = /500.html { root /webapps/www/my_project/my_app/static/; } } 

So: gunicorn is running, nginx works ... what tests (and how?) Should I run to determine if gunicorn wsgi is working correctly (and if nginx proxies the specified material correctly)?

Edit: I narrowed the problem down to communication between the gun and nginx through the unix socket. If I change the $ SOCKFILE bound to 0.0.0.0:80 and stop nginx, the application pages will be sent from my site. The bad news is that the lines of the socket file are the same between the two conf files, so I don't know why they are not reporting. I suppose this means that nginx is incorrectly retrieving and passing data through?

+7
source share
2 answers

Go to the project directory:

 cd projectname gunicorn --log-file=- projectname.wsgi:application 

and

 sudo systemctl status gunicorn 
+1
source

I actually did a damn good tutorial on setting up Django + Nginx + Gunicorn.
Take a look, this should be clear.

https://reduxblog.com/post/setting-django-nginx-gunicorn-postgresql/

0
source

Source: https://habr.com/ru/post/1246851/


All Articles