python - nginx-gunicorn Flask 应用程序未指向我在 CentoOS 7 上的应用程序目录
问题描述
我正在尝试在 Centos7 服务器上部署一个小烧瓶应用程序,我按照本指南nginx
中的段落进行了基本设置/etc/nginx/conf.d/microblog.conf
:
server {
# listen on port 80 (http)
listen 80;
server_name _;
location / {
# redirect any requests to the same URL but on https
return 301 https://$host$request_uri;
}
}
server {
# listen on port 443 (https)
listen 443 ssl;
server_name _;
# location of the self-signed SSL certificate
ssl_certificate /home/cocchi/git_dir/covid20/certs/cert.pem;
ssl_certificate_key /home/cocchi/git_dir/covid20/certs/key.pem;
# write access and error logs to /var/log
access_log /var/log/covid20_access.log;
error_log /var/log/covid20_error.log;
location / {
# forward application requests to the gunicorn server
proxy_pass http://127.0.0.1:8000;
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;
}
location /static {
# handle static files directly, without forwarding to the application
alias /home/cocchi/git_dir/covid20/app/static;
expires 30d;
}
}
gunicorn
然后在/etc/systemd/system/covid20.service
(本指南)中设置距离:
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target
[Service]
User=cocchi
WorkingDirectory=/home/cocchi/git_dir/covid20
Environment="PATH=/home/cocchi/git_dir/covid20/venv/bin"
ExecStart=/home/cocchi/git_dir/covid20/venv/bin/gunicorn -b localhost:8000 -w 4 microblog:app
[Install]
WantedBy=multi-user.target
现在当我访问 HTTPS 网站时,我可以看到它flask
以某种方式工作,因为它会自动重定向到,auth/login
但我nginx error
看到了/var/log/nginx/error.log
:
2020/04/24 19:19:46 [error] 8391#0: *6 open() "/usr/share/nginx/html/auth/login" failed (2: No such file or directory), client: 10.40.1.217, server: _, request: "GET /auth/login?next=%2F HTTP/1.1", host: "192.168.50.3"
显然与nginx
未指向我的项目目录home/cocchi/git_dir/covid20
但仍指向默认值的事实有关/usr/share/nginx/html
,我不明白为什么。
我还将目录的所有权更改为 nginx,然后更改为我的用户,但没有成功:
ls -ls /home/cocchi/git_dir/
0 drwxrwxr-x 10 cocchi nginx 335 Apr 24 17:23 covid20
我想知道几个指南和网站,但一无所获,有人知道吗?当然这很简单,我在这里失去了一些东西......
非常感谢您的帮助!