Nginx默认网站路径位于子目录而非/(根)中

我想配置我的站点,使其在子目录而不是mydomain/中运行。我的意思是希望不要从mydomain/myproject看到它,而是去mysite.com/看该网站。 我正在使用uwsgiflask网站进行通信,这是我的/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:

我正在使用 uwsgi 版本2.0.18和 nginx /1.14.0(Ubuntu) 谢谢

ljj007969 回答:Nginx默认网站路径位于子目录而非/(根)中

尝试一下...

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;

    }

编辑:因此,我的结论是,在FlaskApp中使用“ /”(根)时,uwsgi ini中的fixpathinfo似乎不起作用。如果Flask使用“ /”,则应在NGINX Config中设置rewrite /be/(.*) /$1 break;

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

本文链接:https://www.f2er.com/3134932.html

大家都在问