D
D
Denis Kazakov2020-01-10 19:25:18
Nginx
Denis Kazakov, 2020-01-10 19:25:18

Why is the URL duplicated?

Problem : I get " https://example.com,example.com/some-uri/ " instead of " https://example.com/some-uri/ ".
There are no errors in error.log and nothing in access.log, because the request is not received. On localhost without, respectively, nginx everything works fine. So it looks like the problem is somewhere between Flask and Nginx.
The site correctly returns responses if the URL ends with a slash, for example:

  • https://example.com/admin/ - works
  • https://example.com/admin - not working

The problem always occurs when Flask returns redirect(url_for(...)). But I don't know what's going on inside Flask-admin and others, so I can't claim that the problem is with redirects.
My nginx config (/etc/nginx/nginx.conf did not change):
server {
    server_name example.com www.example.com;
    root /path/to/app;

    listen 443 ssl;                                                    
    //...

    location / {
        include          /etc/nginx/proxy_params;
        proxy_pass       http://127.0.0.1:8000;
        proxy_set_header Host            $host;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ \.(jpg|jpeg|png|gif|js|txt|pdf) {
        root /path/to/static/;
    }
}

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    }                                               

    if ($host = example.com) {
        return 301 https://$host$request_uri;
    }                                               

    listen 80;
    server_name example.com www.example.com;
    return 404;                                     
}

What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mahmudchon, 2020-01-10
@mahmudchon

I think you are missing try_files here . Now the link with / works for you , because in fact there is such a folder. As an example:

...
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question