phpStudy2018 Nginx404

vance發表於2019-07-02

問題描述

phpStudy2018 使用php7+nginx,前半天還一直沒問題,也不知道怎麼了,後面加了一個站點配置,就突然出現404問題,檢視日誌

2019/07/02 19:56:12 [error] 12448#1000: *1 CreateFile() "D:/homestead/code/**/api/public/api/login" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: **-api.local, request: "POST /api/login HTTP/1.1", host: "**-api.local"

1,查詢許多關於目錄斜槓問題

在Windows系統中,正斜槓 / 表示除法,用來進行整除運算;反斜槓 \ 用來表示目錄。
在Unix系統中,/ 表示目錄;\ 表示跳脫字元將特殊字元變成一般字元(如enter,$,空格等)。

然後就將vhosts.conf配置檔案和nginx.conf的root都改為正斜槓

2,訪問配置的虛擬目錄時,可以訪問到框架的入口檔案,但無法訪問到虛擬目錄對應的模組(啟用了專案分組)

整合環境自動生成的vhost.conf檔案中缺少兩行配置語句句

if (!-e $request_filename) {

    rewrite ^/(.*)$ /index.php/$1 last;

}

這兩句話的意思是指,如果請求的檔案不存在,則進行路徑的重寫

改完以後的vhost.conf檔案內容為


server {
        listen       80;
        # 網站域名
        server_name  demo.local ;
        # 程式碼根目錄
        root   "D:/homestead/code/demo/api/public";
        location / {
             # 預設請求的檔案排序
            index  index.html index.htm index.php;
            # 判斷請求的檔案是否存在
            if (!-e $request_filename) {
                 # 如果不存在就進行重定向
                rewrite ^/(.*)$ /index.php/$1 last;
            }
            #autoindex  on;
        }
        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;
        }
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結
vance