Nginx + Systemd/Systemctl + Django not working (502 bad gateway) -


i've been @ hours , yet cannot figure out why setup isn't working. if run command that's in exec on own, can access page through browser fine. when try run service, 502: bad gateway.

i first tried using unix sockets, when didn't work, plugged in ip , port directly, still no luck.

gunicorn.service:

[unit] description=gunicorn daemon after=network.target  [service] user=username workingdirectory=/home/username/naomiselect environment="path=/home/username/naomiselect/naomienv/bin" execstart=/home/username/naomiselect/naomienv/bin/gunicorn --workers 3 --bind local_ip:8000 naomiselect.wsgi:application  [install] wantedby=multi-user.target 

nginx.conf:

user www-data; worker_processes auto; pid /run/nginx.pid;  events {     worker_connections 768;     # multi_accept on; }  http {      ##     # basic settings     ##      sendfile on;     tcp_nopush on;     tcp_nodelay on;     keepalive_timeout 65;     types_hash_max_size 2048;     # server_tokens off;      # server_names_hash_bucket_size 64;     # server_name_in_redirect off;      include /etc/nginx/mime.types;     default_type application/octet-stream;      ##     # ssl settings     ##      ssl_protocols tlsv1 tlsv1.1 tlsv1.2; # dropping sslv3, ref: poodle     ssl_prefer_server_ciphers on;      ##     # logging settings     ##      access_log /var/log/nginx/access.log;     error_log /var/log/nginx/error.log;      ##     # gzip settings     ##      gzip on;     gzip_disable "msie6";      # gzip_vary on;     # gzip_proxied any;     # gzip_comp_level 6;     # gzip_buffers 16 8k;     # gzip_http_version 1.1;     # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;      ##     # virtual host configs     ##      include /etc/nginx/conf.d/*.conf;     include /etc/nginx/sites-enabled/*; } 

sites-available/naomiselect:

server {     listen 80;     server_name local_ip;      location = /favicon.ico { access_log off; log_not_found off; }     location /static/ {         root /home/username/naomiselect;     }      location / {         proxy_set_header host $http_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;         proxy_pass http://local_ip:8000/;     } } 

the directory group , owner www-data , username, respectively, recursively, permissions drwxrwxr-x.

i have no idea i'm doing incorrectly when i've referenced several tutorials , tried different methods , none of them work.

so (in comments) status gunicorn.service says "exited" rather "running" after start it.

most of times, means service type= misconfiguration. default type=simple, expects non-forking process. probably, daemon forks background after startup, confuses systemd:

if set simple (the default if neither type= nor busname=, execstart= specified), expected process configured execstart= main process of service.

if set forking, expected process configured execstart= call fork() part of start-up. parent process expected exit when start-up complete , communication channels set up.

so, check hypothesis, run daemon binary shell. if releases shell immediately, daemon "forking" , need pass corresponding option in unit file:

[service] type=forking 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -