【问题标题】:Nginx default website path in subdirectory rather than / (root)Nginx 默认网站路径在子目录而不是 / (root)
【发布时间】:2020-03-05 12:51:20
【问题描述】:

我想配置我的站点,使其在子目录而不是mydomain/ 中运行。我的意思是,我希望从mydomain/myproject 看到它,而不是去 mysite.com/ 并查看该网站。 我正在使用uwsgi 与烧瓶网站交谈,这是我的/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) 谢谢

【问题讨论】:

    标签: nginx webserver nginx-config


    【解决方案1】:

    试试这个...

    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 中使用“/”(root)时,uwsgi ini 中的 fixpathinfo 似乎不起作用。如果 Flask 使用“/”,你应该在 NGINX Config 中设置rewrite /be/(.*) /$1 break;

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

    【讨论】:

    • 什么是fixpathinfo
    • 它仍然给not found
    • 此操作允许您在 nginx 中设置 SCRIPT_NAME 而无需费心重写 PATH_INFO(这是 nginx 无法承受的)uwsgi-docs.readthedocs.io/en/latest/Changelog-2.0.11.html
    • 您是否尝试在您的 ini 文件中配置挂载点?像 mount = /app1=app1.py?
    • aaahh ...我想我知道它在哪里...我认为您在您的flaskapp中使用“/”(root)对吗?所以改变“rewrite /myproject/(.+) /$1 break;”到“重写/myproject//break;”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    相关资源
    最近更新 更多