4
使用nginx从URL中删除尾部斜杠
我希望我的网站上的以下URL是等效的: /foo/bar /foo/bar/ /foo/bar/index.html 此外,我希望后两种形式向第一种形式发出HTTP 301重定向。我只是在提供静态页面,它们是按照第三种形式排列的。(换句话说,当用户请求时,/foo/bar他们应在处接收文件/usr/share/.../foo/bar/index.html)。 我的nginx.conf当前包含以下内容: rewrite ^(.+)/$ $1 permanent; index index.html; try_files $uri $uri/index.html =404; 这适用于的请求/foo/bar/index.html,但是当我的请求/foo/bar或/foo/bar/Safari告诉我“发生了太多重定向”时,我认为存在无限的重定向循环或类似的循环。如何获取nginx以上述方式将URL映射到文件? 编辑:我的完整配置 这是我的全部nginx.conf,我的域名替换为“ example.com”。 user www-data; worker_processes 1; pid /run/nginx.pid; events { worker_connections 768; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; server_tokens off; server_names_hash_bucket_size 64; include /etc/nginx/mime.types; …
14
nginx