nginx 配置php访问

nginx中配置可访问php文件,并实现php  pathinfo。nginx.conf配置文件如下:



server {
listen 8080 default_server;
listen [::]:8080 default_server ipv6only=on;

root /var/www/html;
index index.html index.htm index.php;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
# Make site accessible from http://localhost/
server_name localhost;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
autoindex on;
# Uncomment to enable naxsi on this location
if (!-e $request_filename) {
rewrite ^/(.*.php)(.*)$ /(.*.php)?s=$1 last;
rewrite ^(.*)$ /(.*.php)?s=$1 last;
break;
}
}

location ~ \.php$ {
#root ;
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
set $path_info '';
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /var/www/html/$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}

location ~ /\.ht {
deny all;
}
}

 

posted on 2016-06-29 14:03  宁静vs致远  阅读(675)  评论(0编辑  收藏  举报

导航