我已经为此工作了几个小时,但我无法弄清楚为什么我的设置不起作用。如果我自己运行 exec 中的命令,我可以通过浏览器访问该页面。但是当我尝试将它作为服务运行时,我得到一个 502: Bad Gateway。
我第一次尝试使用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-data 和用户名,递归地,具有权限 drwxrwxr-x。
当我参考了几个教程并尝试了不同的方法但它们都不起作用时,我不知道自己做错了什么。