本重写规则巧妙利用了try_file和if来支持子目录部署项目时的URL重写支持。
server {
listen 80;
listen [::]:80 default ipv6only=on;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name localhost;
location / {
# URL重写支持
try_files $uri $uri/ /index.php?s=$uri&$args;
# URL重写支持子目录部署支持
if (!-e $request_filename) {
rewrite ^(/.+?/)(.*)$ $1index.php?s=/$2 last;
break;
}
}
# pathinfo支持配置
#
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
如果不会配置可以加群咨询 105108204最佳答案
