我一直在這個小時,但我想不通爲什麼我的設置不工作。如果我自己運行exec中的命令,我可以通過瀏覽器訪問該頁面。但是當我嘗試將它作爲服務運行時,我得到一個502:錯誤的網關。Nginx + Systemd/Systemctl + Django無法正常工作(502壞的網關)
我第一次嘗試使用Unix套接字,但是當它不起作用時,我只是直接插入IP和端口,仍然沒有運氣。
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/*;
}
網站可用/ 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/;
}
}
目錄組和所有者是www數據和用戶名,分別遞歸,權限爲drwxrwxr-x。
我不知道我做錯了什麼,當我參考了幾個教程,並嘗試不同的方法和無他們的工作。
A 502響應意味着上游服務器無法連接。你確定gunicorn正在運行嗎? – jedifans
我不認爲它在運行,沒有。狀態顯示服務「退出」而不是「正在運行」。不知道它爲什麼只是退出。 – tayoung
'journalctl -xe'中的任何內容爲什麼會退出? – jedifans