nginx下,隐藏index.php,并且解决二级目录的问题,弄了一上午,弄好了,特此分享。
首先是nginx.conf
server {
fastcgi_intercept_errors on;
listen 80;
server_name localhost;
charset utf-8;
root E:/php;
index index.php index.html index.htm;
location / {
autoindex on;
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite (/[a-z0-9]+/)(.+) $1index.php/$2;
}
location ~* /protected/.* {
deny all;
}
location ~ /\.ht {
deny all;
}
include alias/*.conf;
location ~* \.php/?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:/php$fastcgi_script_name;
include fastcgi_params;
}
}
然后是虚拟目录的配置,我这里暂时只要用到phpmyadmin,所以只有这个
location ~* /phpmyadmin.* {
alias G:/server/bin/phpmyadmin;
index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME G:/server/bin$fastcgi_script_name;
include fastcgi_params;
}