【发布时间】:2023-03-03 00:40:01
【问题描述】:
我已经浏览了一些以前的线程: How do I set subdirectory in nginx with Django how to deploy django under a suburl behind nginx Serving flask app on subdirectory nginx + uwsgi
基本的教训是,您应该只需要配置您的站点(可用)来实现这一点。我现在尝试了
的各种排列server {
listen 80;
server_name www.example.com;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
root /path/to/project;
}
location /project/ {
root /path/to/project;
include /etc/nginx/uwsgi_params;
uwsgi_param SCRIPT_NAME /project;
uwsgi_modifier1 30;
uwsgi_param PATH_INFO "$1";
uwsgi_pass unix:/tmp/project.sock;
}
}
当我将位置定义为“/”时,一切都运行良好(删除 SCRIPT_NAME、修饰符1、PATH_INFO 和 root 无关紧要。但尝试使用子目录总是会导致找不到页面 (404):
Request URL: http://www.example.com/project/project
(编辑)它在请求中添加一个目录。我不明白什么?
(尝试过的forced_script_name - 不应该使用它并给其他类型的头痛 - 和uwsgi配置设置)
编辑:
location /project/ {
root /path/to/project;
include /etc/nginx/uwsgi_params;
uwsgi_param SCRIPT_NAME /project;
uwsgi_pass unix:/tmp/project.sock;
}
不工作......当我为 / 配置时,套接字在那里并且工作 - 我只是看不到我缺少什么。
更新:
location ~ /project(?<path_info>/.*|$) {
include /etc/nginx/uwsgi_params;
uwsgi_pass unix:/tmp/project.sock;
uwsgi_param PATH_INFO $path_info;
uwsgi_param SCRIPT_NAME /project;
}
这会加载网站,但所有链接都指向 http://example.com/link/to/something 而不是 http://example.com/project/link/to/something
【问题讨论】:
-
django 1.9.2, uwsgi 2.07-debian(在 ubuntu 15.10 服务器上运行)
标签: django nginx uwsgi subdirectory