S
S
Sergey Khlopov2021-08-06 10:05:46
Nginx
Sergey Khlopov, 2021-08-06 10:05:46

Why does a 302 redirect from slash to no slash happen?

Hello, please tell me, there seems to be nothing in the config about redirects from a slash to without a slash, but for some reason such a redirect occurs. Has anyone encountered this? .htaccess doesn't work because apache is not on the server. The site itself does not seem to do such a redirect either.

# www redirect
server {
    listen       {ip}:80;
    server_name  www.domain.com;

    add_header   Cache-Control "max-age=315360000, public";
    add_header   X-Frame-Options "DENY";

    root         /var/empty;

    return       301 https://domain.com$uri;
}


server {
    listen       {ip}:443 ssl;
    server_name  www.domain.com;

    ssl			       on;
    ssl_certificate            /etc/nginx/certs/domain.com.chained.crt;
    ssl_certificate_key        /etc/nginx/certs/domain.com.key;


    add_header   Cache-Control "max-age=315360000, public";
    add_header   X-Frame-Options "DENY";

    root         /var/empty;

    return       301 https://domain.com$uri;
}


# HTTP -> HTTPS redirect
server {
    listen       {ip}:80;
    server_name  domain.com;

    root        /var/www/domain.com/site/public;

    location = /robots.txt {
       break;
    }

    location = /sitemap.xml {
        break;
    }

    location / {
        add_header   Cache-Control "max-age=315360000, public";
        add_header   X-Frame-Options "DENY";

        return       301 https://domain.com$uri;
    }
}


server {
    listen      {ip} ssl http2;
    server_name domain.com;


    root      /var/www/domain.com/site/public;
    error_log /var/www/domain.com/logs/error.log;

    index     index.html index.htm index.php;
    
    include   includes/deny-files.conf;

    # SSL
    add_header  Strict-Transport-Security "max-age=0;";
    ssl                        on;
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_stapling               on;
    ssl_stapling_verify        on;

    ssl_buffer_size            8k;

    ssl_certificate            /etc/nginx/certs/domain.com.chained.crt;
    ssl_certificate_key        /etc/nginx/certs/domain.com.key;

    ssl_ciphers                "code";
    ssl_prefer_server_ciphers  on;

    ssl_session_cache          shared:SSL:10m;
    ssl_session_timeout        10m;

    # gzip
    gzip                       on;
    gzip_comp_level            5;
    gzip_types                 text/plain text/css text/javascript application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss font/opentype application/font-woff application/x-font-woff font/woff font/woff2 application/font-woff2  image/svg+xml;

    client_max_body_size 64m;
    charset	         utf-8;    
    
    # pagespeed config
    pagespeed on;

    # Needs to exist and be writable by nginx.  Use tmpfs for best performance.
    pagespeed FileCachePath /var/ngx_pagespeed_cache;

    # Ensure requests for pagespeed optimized resources go to the pagespeed handler
    # and no extraneous headers get set.
    location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
       add_header "" "";
    }
    location ~ "^/pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon$" { }

    pagespeed Disallow "*.svg";
    pagespeed DisableRewriteOnNoTransform off;
    pagespeed RespectVary off;    
    pagespeed LowercaseHtmlNames on;
    pagespeed AddResourceHeader "Access-Control-Allow-Origin" "https://domain.com";

    
    # static caching	
    location ~ \.(js|css)$ {
        add_header                 Cache-Control public;
        fastcgi_hide_header        Set-Cookie;

        open_file_cache            max=10000 inactive=14d;
        open_file_cache_errors     on;
        open_file_cache_min_uses   3;
        open_file_cache_valid      1m;
        output_buffers             1  2m;

        expires                    14d;
        etag			   		   on;	
    }

    location ~ \.(png|PNG|jpg|JPG|jpeg|JPEG|gif|swf|ico|svg|otf|tiff|woff|woff2)$ {
        add_header                 Cache-Control public;
        fastcgi_hide_header        Set-Cookie;

        open_file_cache            max=10000 inactive=31d;
        open_file_cache_errors     on;
        open_file_cache_min_uses   3;
        open_file_cache_valid      1m;
        output_buffers             1  2m;

        expires                    200d;
        etag                       on;
    }


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


    location ~ \.php$ {
        fastcgi_pass            unix:/run/php/php7.1-fpm.sock;
        fastcgi_index           index.php;
        fastcgi_param           SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param HTTPS     on;
        fastcgi_connect_timeout 120s;
        fastcgi_read_timeout    300;
        include                 fastcgi_params;
    }
}

Thank you in advance for your response

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question