server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; root "E:/phpStudy/WWW"; location / { index index.html index.htm index.php l.php; autoindex off; #如果請求既不是一個文件,也不是一個目錄,則執行一下重寫規則 if (!-e $request_filename) { #地址作為將參數rewrite到index.php上。 rewrite ^/(.*)$ /index.php/$1; #若是子目錄則使用下面這句,將subdir改成目錄名稱即可。 #rewrite ^/subdir/(.*)$ /subdir/index.php/$1; } } #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 html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
編輯Nginx配置文件 一般在 /etc/nginx/conf.d 目錄下 紅色部分按如上配置