I'm new to Django. I have a Django project and in my project, I use multiple APIs such as blockchain API for handling bitcoin transactions and cryptocompare API to get the latest bitcoin price and in my project, I have WebSocket messenger. I have set up the NGINX and Gunicorn for my production.
but all of the POST and GET requests in my project don't work and my project cannot communicate with external API and even local service like blockchain wallet API service. but when I run my project only with gunicorn
like this :
gunicorn --bind 0.0.0.0:80 myproject.wsgi
it works fine
I'm a little bit confused.
here is my Gunicorn service in ubuntu server 18
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/home/myproject
ExecStart=/home/env/bin/gunicorn --access-logfile - --workers 5 --worker-class gevent --bind unix:/home/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
And here is my Nginx configuration :
upstream channels-backend {
server localhost:9001;
}
upstream django {
server myproject:80;
}
server {
listen 80;
server_name Domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/myproject;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
expires 1y;
add_header Cache-Control "max-age=31536000";
}
location / {
include proxy_params;
proxy_pass http://unix:/home/myproject/starbitsite.sock;
}
#websocket
location /ws/myprojectname/index/ {
proxy_pass http://channels-backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
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-Host $server_name;
}
}