D
D
Dmitry2016-05-29 09:25:07
Nginx
Dmitry, 2016-05-29 09:25:07

Where did the cyclic redirect come from?

When I try to open the page everything works fine. Except for some files.
Part of the statics is given with a redirect.
For example, there is a picture
am49.ru/uploads/2016/05/am49.ru.f941d38af67781d48b...
When you try to show it on the page, it makes several redirects. As a result, the address of the picture is
94.247.56.247/94.247.56.247/94.247.56.247/94.247.5...
Some of the pictures, from the same path, return normally, without the redirect
am49.ru/uploads/2016/05/am49. ru.f941d38af67781d48b... The
bug does not depend on the file name/mask: the same problem with
am49.ru/talk/style_images/ip.boardpr/logo4.jpg
Different images can have a different number of redirects - somewhere 2, where - something rests on the browser limit.
The config for tests left like this, minimal. The redirect didn't disappear.

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include    /etc/nginx/mime.types;    
    index    index.html index.htm index.php;
    default_type application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                      '$upstream_cache_status';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    send_timeout 300s;
    
    types_hash_max_size 2048;

    server_tokens off;

    server {
        listen       80 default_server;
        server_name  am49.ru;

        location / {

            proxy_redirect          off;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        Accept-Encoding "";
            client_max_body_size    328M;
            client_body_buffer_size 328k;
            proxy_connect_timeout   90;
            proxy_send_timeout      90;
            proxy_read_timeout      90;
            proxy_buffers           32 4k;

            proxy_set_header Host 'am49.ru';
            proxy_pass   http://127.0.0.1:8080;
        }

        location ~* \.(gif|jpg|jpeg|png|bmp|mp4|flv)$ {
            root    /home/auto.magadan.ru/html/;

            access_log   off;
            expires  max;
            add_header Last-Modified "";

            try_files $uri $uri/ =404;
        }
    }
}

The mime.types file is standard, the one that nginx did during installation. Didn't change.
nginx version: nginx/1.6.3
In nginx -V looked like the config is using only one file. I edit it. Others don't connect.
In which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Romanenko, 2016-05-29
@dimasmagadan

nginx first uses rules without regular expressions, most likely you work out the first rule.
how to check:
turn on debug logging and see the path
how to fix it:
include the second location in the first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question