nginx serving Django in a subdirectory through uWSGI

前端 未结 5 2034
别跟我提以往
别跟我提以往 2021-02-19 15:48

I have already gone through some previous threads: How do I set subdirectory in nginx with Django how to deploy django under a suburl behind nginx Serving flask app on subdirect

5条回答
  •  自闭症患者
    2021-02-19 16:25

    Cleanest Method for Latest Nginx/uWSGI Versions

    Since uwsgi_modifier1 30 is removed in the latest versions and I felt like the mount-point stuff was too hacky, I had to use a newer method to serve Django in a subdirectory:

    uWSGI config:

    [uwsgi]
    socket =        /tmp/project.sock
    
    # Requires PCRE support compiled into uWSGI
    route-run =     fixpathinfo:
    

    Nginx config:

    location /project {
        include         /etc/nginx/uwsgi_params;
        uwsgi_pass      unix:/tmp/project.sock;
        uwsgi_param     SCRIPT_NAME /project; # Pass the URL prefix to uWSGI so the "fixpathinfo:" route-rule can strip it out
    }
    

    NOTE: fixpathinfo: requires PCRE support to be compiled into uWSGI.

    So if things aren't working, try installing libpcre and libpcre-dev, then recompile 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.

提交回复
热议问题