Nginx子目录中的默认网站路径,而不是/(根)

问题描述 投票:0回答:1

我想配置我的站点,使其在子目录中而不是在mydomain/中运行。我的意思是希望不要从mydomain/myproject中看到它,而是去mysite.com/并查看该网站。我正在使用uwsgi与flask网站进行通信,这是我的/etc/nginx/sites-available/myproject配置文件。

server {
    server_name mydomain www.mydomain;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/root/Desktop/myproject/myproject.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.mydomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mydomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name mydomain www.mydomain;
    return 404; # managed by Certbot

}

我试图将代码从location /更改为location /myprojectlocation = /myproject,但是找不到它!

添加的信息这是我的config.ini文件

[uwsgi]
module = server:app

master = true
processes = 5

socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true

route-run = fixpathinfo:

谢谢

nginx webserver nginx-config
1个回答
0
投票

尝试一下...

NGINX配置:


location /mylocation {
        include uwsgi_params;
        uwsgi_pass unix:/myproject/myproject.sock;
        uwsgi_param SCRIPT_NAME /mylocation;
    }

uwsgi ini文件:

route-run = fixpathinfo:

编辑:我用重写我的nginx配置中的路径来尝试它,并且它起作用了..在您的wsgi ini文件中没有什么特别的配置!

location /be {
    rewrite /be/(.+) /$1 break;
        include uwsgi_params;
        uwsgi_pass unix:/myproject/myproject.sock;

    }

谢谢Cyber​​Dem0n !!Nginx - Rewrite the request_uri before uwsgi_pass

© www.soinside.com 2019 - 2024. All rights reserved.