Run django app via nginx+uwsgi in a subpath

后端 未结 3 2039
无人及你
无人及你 2020-12-08 05:34

I want to run a simple test project in a subdirectory alias on our development server. The basic setup is an nginx with a location that passes everything in a subdirectory t

3条回答
  •  甜味超标
    2020-12-08 06:25

    Now that uwsgi_modifier1 30 is removed in the latest versions of Nginx and uWSGI (and I didn't feel like using some hacky rewrite rules), I had to find a newer method to get it working:

    uWSGI config:

    [uwsgi]
    # Requires PCRE support compiled into uWSGI
    route-run = fixpathinfo:
    

    Nginx config:

    server {
        location /fancyprojectname/static {
            alias /srv/fancyprojectname/static;
        }
    
        location /fancyprojectname {
            uwsgi_pass unix://var/run/uwsgi/app/fancyprojectname/socket;
            uwsgi_param SCRIPT_NAME /fancyprojectname; # Pass the URL prefix to uWSGI so the "fixpathinfo:" route-rule can strip it out
            include uwsgi_params;
        }
    }
    

    IF THAT DOESN'T FIX IT: Try installing libpcre and libpcre-dev, then reinstall uwsgi with pip install -I --no-cache-dir uwsgi. uWSGI's internal routing subsystem requires the PCRE library to be installed before uWSGI is compiled/installed. More information on uWSGI and PCRE.

提交回复
热议问题