如何将url参数传递给Flask behind Nginx proxy_pass with unix s

2024-06-25 23:59:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用bjoern作为python服务器的Flask应用程序。我的一个示例url类似于:

http://example.com/store/junihh
http://example.com/store/junihh/product-name

其中“junihh”和“product name”是我需要传递给python的参数。在

在阅读了针对TCP/IP调用的性能之后,我尝试使用unixsocket。但是现在我在浏览器上发现了502错误。在

以下是我的配置片段:

^{pr2}$

如何使用unix socket通过Nginx proxy_pass将url参数传递给Flask?在

谢谢你的帮助。在


Tags: storename服务器com应用程序httpurlflask
1条回答
网友
1楼 · 发布于 2024-06-25 23:59:25

这是我的配置,它可以工作。502是因为它找不到到到上游服务器的路由(例如,将http://127.0.0.1:5000/$1改为http://localhost:5000/$1)将导致502。在

在nginx.conf公司

http {
    server {
        listen       80; 
        server_name  localhost;

        location ~ ^/store/(.*)$ {
            proxy_pass http://127.0.0.1:5000/$1;
        }   
    }   
}

烧瓶应用程序副本

^{pr2}$

更新

或者您可以像这样使用unix套接字,但是中继到uwsgi。在

在nginx.conf公司

http {
    server {
        listen       80; 

        location /store {
            rewrite /store/(.+) $1 break;
            include uwsgi_params;
            uwsgi_pass unix:/tmp/store.sock;
        }   
    }   
}

烧瓶应用程序副本

就像上面说的,不是改变

uwsgi配置

[uwsgi]
module=app:app
plugins=python3
master=true
processes=1
socket=/tmp/store.sock

uid=nobody
gid=nobody

vaccum=true
die-on-term=true

另存为config.ini,然后运行uwsgi config.ini

nginx重新加载后,您可以访问您的页面;-)

相关问题 更多 >