天天看點

phpstudy的php項目在nginx環境下404、403錯誤

1、在vhost-ini檔案上配置下面

location / {
    if (!-e $request_filename) {
     rewrite ^(.*)$ /index.php?s=/$1 last;
     break;
    }
}

           

2、完整如下

server {
        listen       80;
        server_name  house.xxx.com ;
        root   "E:\code\www\html\web\xxx\public";
	    location / {
          if (!-e $request_filename) {
             rewrite ^(.*)$ /index.php?s=/$1 last;
             break;
          }
        }
        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;
        }
}

           

3、403錯誤

當通路該網站的時,nginx 會按照 index.html,index.htm ,index.php 的先後順序在根目錄中查找檔案。如果這三個檔案都不存在,那麼nginx就會傳回403 Forbidden。

是以,在vhost裡沒有這段内容直接輸入域名通路就會報403的錯誤,除非你在域名後面加個 /index.php才可以正常通路;

phpstudy的php項目在nginx環境下404、403錯誤