nginx子路径下反代运行django

方案一

uWSGI config:

[uwsgi]
# 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.cnblogs.com/jonnyan/p/14832643.html