正在设置一个nginx服务器。 我想添加一些location块,只允许index.html或index.php的父文件夹被提供,但会自己redirectindex.html或index.php 。
我也希望server条目将redirect以斜杠结尾的文件夹为非斜杠版本。
例如:
http://www.example.com/about ---> good http://www.example.com/about/ ---> redirects to http://www.example.com/about http://www.example.com/about/index.html ---> redirects to http://www.example.com/about
这里是我有的一个sites-available文件,缩写为MCVE,并删除任何额外的信息。
server { listen 80; root /var/www/html; index index.php index.html index.htm; ssi on; server_name example.com; location ~ /\. { access_log off; log_not_found off; deny all; } location ~ ~$ { access_log off; log_not_found off; deny all; } location ~ \.php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } }
我的猜测是这样的两个项目:
location ~ / { try_files $uri(strip /) =404; } location ~ index.* { try_files $uri(strip *) =404; }