Ubuntu16.04 nginx+uwsgi二級目錄

筆者在同一臺服務(wù)器上部署了django和php,為了使兩者共存而想到了將django項(xiàng)目部署到二級目錄下,而nginx則使用的反向代理

django中uwsgi的配置文件

[uwsgi]
chdir = /var/www/html/api
module = api.wsgi
master = true
processes = 10
#socket = :8080
http = :8080
vacuum = true
pidfile = /tmp/uwsgi.pid

nginx默認(rèn)是將用戶的請求通過socket與django通信,如果使用了nginx的反向代理之后訪問則會通過http與django通信,所以上面的配置文件中需要將socket注釋掉,取而代之的則是http = :8080。

主要需要修改的是nginx的配置文件

upstream django {
    server 127.0.0.1:8080;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
    
    location /api {
        # 這里為django項(xiàng)目的配置內(nèi)容
        uwsgi_pass django;
        proxy_pass http://django/api;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        include /var/www/html/api/uwsgi_params;
    }

    location ^~ /api/static {
        alias /var/www/html/bill/static;
    }   

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

在瀏覽器中則可以使用http://服務(wù)器IP/api/,訪問到django項(xiàng)目

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容