我想配置我的站点,使其在子目录而不是mydomain/
中运行。我的意思是希望不要从mydomain/myproject
看到它,而是去mysite.com/看该网站。
我正在使用uwsgi
与Flask网站进行通信,这是我的/etc/nginx/sites-available/myproject
配置文件。
server {
server_name mydomain www.mydomain;
location / {
include uwsgi_params;
uwsgi_pass unix:/root/Desktop/myproject/myproject.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.mydomain) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mydomain) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name mydomain www.mydomain;
return 404; # managed by Certbot
}
我试图将代码从location /
更改为location /myproject
或location = /myproject
,但找不到它!
添加的信息
这是我的config.ini
文件
[uwsgi]
module = server:app
master = true
processes = 5
socket = myproject.sock
chmod-socket = 660
vacuum = true
die-on-term = true
route-run = fixpathinfo:
我正在使用 uwsgi 版本2.0.18和 nginx /1.14.0(Ubuntu) 谢谢
答案 0 :(得分:1)
尝试一下...
NGINX配置:
location /mylocation {
include uwsgi_params;
uwsgi_pass unix:/myproject/myproject.sock;
uwsgi_param SCRIPT_NAME /mylocation;
}
uwsgi ini文件:
route-run = fixpathinfo:
编辑: 我尝试通过在nginx配置中重写路径来尝试它,并且它起作用了..在您的wsgi ini文件中没有什么特别的配置!
location /be {
rewrite /be/(.+) /$1 break;
include uwsgi_params;
uwsgi_pass unix:/myproject/myproject.sock;
}
编辑:因此,我的结论是,在FlaskApp中使用“ /”(根)时,uwsgi ini中的fixpathinfo似乎不起作用。如果Flask使用“ /”,则应在NGINX Config中设置rewrite /be/(.*) /$1 break;
谢谢CyberDem0n! Nginx - Rewrite the request_uri before uwsgi_pass