nginx访问php程序相关配置

server {
	listen 			*:80;
	charset			utf-8;
    server_name 	roujiaxiaomowang.wanghaokun.com mowang.crucco.com; 
    access_log  	/export/home/logs/third.vancl.com_access.log  	main;
	error_log  		/export/home/logs/third.vancl.com_error.log  	warn;
	#autoindex 		on;
	
	set $web_root 	WEB_ROOT;
    root            $web_root;

    rewrite         ^/(w+)_action/w+/?/?                                 /php_code/controller/$1.php break;
    rewrite         ^/(w+).html  	                                        /html_code/html/$1.html 	break;
    rewrite         ^/(w+).php												/php_code/third/$1.php 		break;
    rewrite         ^/js/(.+).js											/html_code/js/$1.js 		break;
    rewrite         ^/css/(.+)												/html_code/css/$1 		break;
    rewrite         ^/css/(.+).css											/html_code/css/$1.css 		break;
    rewrite         ^/image/(.+).png										/html_code/image/$1.png 	break;
 	rewrite         ^/image/(.+).gif                                       /html_code/image/$1.gif     break;
 	rewrite         ^/image/(.+).jpg  										/html_code/image/$1.jpg     break;

	rewrite 		^/services/bookServiceImpl 							/soap/soap_server_bookitem.php break;
	rewrite 		^/forBookCode/forBookCode_getEbookIdByWareId.action 	/bookitem/Ebook.php	break ;
	rewrite 		^/list.* 												/php/list.php break;
	rewrite 		^/d*.html 											/php/detail.php break;
	rewrite 		^/(w+)$												/php/$1.php break;


	location / {
		#index 	/php/index.php;
    }

 	location ~ .php($|/) {
		include fastcgi_params.default;
        #fastcgi_pass unix:/dev/shm/php-fcgi-search.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php?IF_REWRITE=1;

        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_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;

        fastcgi_param SCRIPT_FILENAME $web_root$fastcgi_script_name;
   }

	error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
	error_page   500 502 503 504  /50x.html;
}

WEB_ROOT改为项目实际要访问的绝对路径

以上rewrite重写中,正则有误,都需要改为以下方式,需要对.进行反斜杠转义进行处理。

rewrite         ^/(w+).php			/php_code/third/$1.php 		break;
原文地址:https://www.cnblogs.com/wanghaokun/p/7607854.html