M
M
Maqsat Batyrqul2016-11-20 13:55:29
Nginx
Maqsat Batyrqul, 2016-11-20 13:55:29

Why does nginx do an infinite redirect?

Good afternoon! Why is that nginx doing an endless redirect to /zabbix->/zabbix/->/zabbix etc, can you help? Where is the mistake?
Link

server {

    server_name site.com;

    merge_slashes off;
    rewrite (.*)//+(.*) $1/$2 permanent;
    rewrite ^/(.*)/$ /$1 permanent;

    error_log  /var/log/nginx/site.com/error.log;
    access_log /var/log/nginx/site.com/access.log;

    root /var/www/site.com/public;
    index index.php index.html index.htm;

    client_max_body_size 100m;

    if ($request_uri ~* "^(.*/)index\.php$") {
        return 301 $1;
    }

    location ~ [A-Z]*\.(css|scss|js|html|svg|eot|ttf|woff) {
    }

    location / {
        if ( $uri != $uri_lowercase ) {
            rewrite . $scheme://$host$uri_lowercase;
        }
        try_files $uri $uri/ /index.php?$query_string;
    }

   location /zabbix {
           root /usr/share/;
           index index.php index.html index.htm;
           location ~ ^/zabbix/(.+\.php)$ {
                   try_files $uri =404;
                   root /usr/share/;
                   fastcgi_pass 127.0.0.1:9000;
                   fastcgi_index index.php;
                   fastcgi_param SCRIPT_FILENAME $request_filename;
                   include /etc/nginx/fastcgi_params;
           }
           location ~* ^/zabbix/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                   root /usr/share/;
           }
   }


    location ~ ^/image/(.*)$ {
        try_files $uri /image.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index image.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi.conf;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi.conf;
    }

    location ~ /\.(ht|git) {
        deny all;
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-11-20
@Maqsat

Most likely the logic is:
/zabbix/ -> /zabbix due to rewrite ^/(.*)/$ /$1 permanent;
/zabbix -> section location /zabbix in which neither location ~ ^/zabbix/(.+\.php)$ nor location ~* ^/zabbix/(.+\.(jpg|jpeg|gif|css|png) works |js|ico|html|xml|txt))$
and jump to location / where try_files ... $uri/ ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question