nginx中配置可訪問php文件,並實現php pathinfo。nginx.conf配置文件以下:php
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; }}