nginx配置vhost

windows系統本地使用nginx服務,偶爾會出現項目接口報異常錯誤或者直接404,
解決辦法如下:

配置下vhost.conf…

server {
        listen       80;
        server_name  mall.me; #可添加多個,多個之間“空格”分開
        #autoindex on;#打開目錄瀏覽,這樣當沒有找到index文件,就也已瀏覽目錄中的文件
        location / {
            root   F:/wnmp/wwwroot/mall;
            index  index.html index.htm index.php;
			 #加一下代碼即可    if(){} 
			 #此處是僞靜態配置
            if (!-e $request_filename) {
            //此處是針對tp的pathinfo
            rewrite ^(.*)$ /index.php?s=$1 last; 
            //下面是針對其他框架
                rewrite  ^(.*)$  /index.php/?/$1  last; 
                break;
            } 

        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   F:/wnmp/wwwroot;
        }
        location ~ \.php$ {
            root           F:/wnmp/wwwroot/mall;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

apache:

在入口文件的同目錄下的.htaccess文件 添加

//線上環境配置
server{
            listen 80;
            root /var/www/mmc-crm/;
            index index.html index.php;
	    server_name   xxx.com;
            client_max_body_size 200m;
            location / {
	       if (!-e $request_filename) {
		        rewrite ^(.*)$ /index.php?s=$1 last;
           		 #rewrite  ^(.*)$  /index.php/?/$1  last;
           		 break;
        	}
		 index  index.html index.htm index.php;
		try_files $uri $uri/ /index.php?$args;
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';

         }
	   
	    location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
	    add_header Access-Control-Allow-Origin *;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token,secretKey,ApiKey';

        }
	access_log /var/log/nginx/api_access.log;
	error_log /var/log/nginx/api_error.log;

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章