uWSGI config:
[uwsgi]
socket = /tmp/project.sock
; mount apps
mount = /app1=app1.py
mount = /app2=app2.py
; rewrite SCRIPT_NAME and PATH_INFO accordingly
manage-script-name = true
Nginx config:
server {
location /subpath/static {
alias /srv/subpath/static;
}
location /subpath {
uwsgi_pass unix://var/run/uwsgi.socket;
uwsgi_param SCRIPT_NAME /subpath; # Pass the URL prefix to uWSGI so the "fixpathinfo:" route-rule can strip it out
include uwsgi_params;
}
}
方案二
uWSGI config:
[uwsgi]
socket = /tmp/project.sock
# Requires PCRE support compiled into uWSGI
route-run = fixpathinfo:
Nginx config:
server {
location /subpath/static {
alias /srv/subpath/static;
}
location /subpath {
uwsgi_pass unix://var/run/uwsgi.socket;
uwsgi_param SCRIPT_NAME /subpath; # Pass the URL prefix to uWSGI so the "fixpathinfo:" route-rule can strip it out
include uwsgi_params;
}
}
方案三
在 settings.py 里,增加以下参数:
FORCE_SCRIPT_NAME = '/subpath'
Reference Link
- https://www.mrdoc.fun/project-7/doc-357/
- https://stackoverflow.com/questions/35792409/nginx-serving-django-in-a-subdirectory-through-uwsgi
- https://stackoverflow.com/questions/48893554/nginx-serving-django-in-subdirectory-admin-login-is-redirecting
- https://jlhxxxx.github.io/nginx-uwsgi.html