简体   繁体   English

烧瓶重定向在生产服务器上附加get%20 /%20HTTP / 1.1)uri。 在当地工作良好

[英]Flask redirect appends get%20/%20HTTP/1.1)uri on production server. Working fine locally

I am trying to redirect all get requests to abc.example.com and send them to example.com. 我正在尝试将所有获取请求重定向到abc.example.com,并将其发送到example.com。 The following works on local: 以下在本地工作:

 @app.route('/', methods=['GET'])
     def message_get():
         return redirect('https://example.com')

But on production server, it fails. 但是在生产服务器上,它会失败。 Instead of getting redirected, the url looks like this: 该URL不会像这样被重定向:

abc.example.comget%20/%20HTTP/1.1)uri abc.example.comget%20 /%20HTTP / 1.1)URI

I observed that if I put in the whole url like this 我观察到,如果我这样输入整个网址

https://abc.example.com https://abc.example.com

it redirects properly. 它正确重定向。 but abc.example.com or http://abc.example.com fails. 但abc.example.com或http://abc.example.com失败。

I have a flask app with gunicorn app server. 我有一个带有gunicorn应用程序服务器的烧瓶应用程序。 Nginx is used as reverse proxy. Nginx用作反向代理。 Unable to determine which of them is causing the problem. 无法确定是哪个引起了问题。 Guessing something to do with my nginx configuration. 猜测与我的nginx配置有关。 But any pointers will help. 但是任何指针都会有所帮助。 thanks. 谢谢。

Nginx configuration: Nginx配置:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name abc.example.com;
        return 301 https://$server_name$request)uri; }

    server{

        # SSL configuration

        server_name abc.example.com;
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;
        include snippets/ssl-abc.example.com.conf;
        include snippets/ssl-params.conf;

        location / {
            include proxy_params;
            proxy_pass http://unix:/home/user1/apps/myapp/myapp.sock;
        }

        location ~ /.well-known {
                    allow all;
            } 
}

You have a typo in your first server section; 您在第一个服务器部分中有一个错字; it should be: 它应该是:

return 301 https://$server_name$request_uri;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM