我设置了“NGINX作为反向代理”+flask+gunicorn。当我在命令行上运行 Gunicorn 时,一切正常并且我可以登录。
# gunicorn --bind xx.xx.xx.xx:5000 run:app
但是当我将gunicorn作为服务启动时,登录页面在登录后会再次重定向到相同的登录页面。所以我无法登录。
这是我的 nginx 配置:
server {
server_name example.com www.example.com;
access_log /var/log/nginx/example.com.access.log ;
error_log /var/log/nginx/example.com.error.log;
add_header X-Proxy-Cache $upstream_cache_status;
location / {
proxy_pass http://xx.xx.xx.xx:5000;
proxy_redirect off;
include proxy_params;
}
# Security settings for better privacy
# Deny hidden files
location ~ /\.(?!well-known\/) {
deny all;
}
# letsencrypt validation
location /.well-known/acme-challenge/ {
alias /var/www/html/.well-known/acme-challenge/;
allow all;
auth_basic off;
}
include /var/www/example.com/conf/nginx/*.conf;
}
nginx 错误日志没有显示任何问题。我也尝试添加以下配置,但没有成功:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
命令行 Gunicorn 工作得非常好。
你有没有弄清楚这一点?抱歉,我没有足够的声誉来发表评论,我也在问。我现在也遇到了同样的问题。