Nginx 尾部斜杠重定向问题

Nginx 尾部斜杠重定向问题

我正在使用 Nginx + Varnish 运行一个 Wordpress 网站。如果我在配置文件中添加或删除尾部斜杠,我会收到页面未正确重定向错误。请提出解决方案,以删除或添加尾部斜杠而不会出现重定向问题。目的是 SEO 避免内容重复问题。谢谢。我的 nginx conf 文件:

server {
listen          8080;
server_name     xyz.de www.xyz.de;
root            /var/www/html/xyz.de;
port_in_redirect off;

index index.html index.htm index.php;

access_log  /var/log/nginx/xyz.de.access.log;
access_log  /var/log/nginx/xyz.de.apachestyle.access.log  apachestandard;
error_log  /var/log/nginx/xyz.de.error.log;

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location = /apple-touch-icon.png { access_log off; log_not_found off; }
location = /apple-touch-icon-precomposed.png { access_log off; log_not_found off; }
location ~ /\. { deny  all; access_log off; log_not_found off; }

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

location ~ \.php$ {
    proxy_intercept_errors on;
    error_page 500 501 502 503 = @fallback;
    fastcgi_buffers 8 256k;
    fastcgi_buffer_size 128k;
    fastcgi_intercept_errors on;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass hhvm;
}
location @fallback {
    fastcgi_buffers 8 256k;
    fastcgi_buffer_size 128k;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass php;
}
location ~* \.(ico|gif|jpe?g|png|svg|eot|otf|woff|woff2|ttf|ogg|js|css)$ {
    expires max;
}

}

相关内容