我正在使用PHP-FastCGI在nginx上运行服务器。目前我进行了设置,以便从我的URL中删除尾部斜杠并发出301重定向。但是,当我访问存在的目录时," err_too_many_redirects"(如果我尝试检查像site.com/images/这样的链接或其他目录链接返回403代码),我的服务器块看起来像这样:
server {
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
rewrite ^/(.*)/$ /$1 permanent;
error_page 404 403 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
internal;
}
location / {
try_files $uri $uri.html $uri/ $uri/index.html $uri/index $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
有人能帮助我找到这个问题的灵魂吗?
答案 0 :(得分:0)
$ uri / term与重写规则一起创建一个循环。试试:
try_files $uri $uri.html $uri/index.html $uri/index =404;