我正在嘗試配置 Nginx 以服務 Django 應用程序和 Laravel 應用程序。我的 Django 應用程序正常工作,所以現在我想從 /snipe-it 獲取 Laravel 應用程序。我正在努力解決的 nginx 配置的主要部分在這里: location /snipe-it/ { alias /var/www/html/public/; #try_files $uri $uri/ /index.php$is_args$args; location ~* \.php(/|$) { try_files $uri $uri/ =404; include fastcgi_params; fastcgi_pass unix:/run/php/php7.3-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }該index.php文件的實際文件位置是/var/www/html/public/index.php。當嘗試訪問位于 的 Laravel 應用程序時http://127.0.0.1/snipe-it/index.php,我收到“文件未找到”。日志輸出如下所示:nginx_1 | - - 24/Jun/2020:17:37:40 +0000 "GET /snipe-it/index.php" 404nginx_1 | 2020/06/24 17:37:40 [error] 17#17: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.30.0.1, server: 127.0.0.1, request: "GET /snipe-it/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.3-fpm.sock:", host: "127.0.0.1"nginx_1 | 172.30.0.1 - - [24/Jun/2020:17:37:40 +0000] "GET /snipe-it/index.php HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0" "-"一切都在一個 docker 容器中,該容器源自使用 Debian buster 的官方 nginx 鏡像。我相信日志中的第一行來自 php-fpm7.3 進程,因為我在文件中設置access.log了。我還希望它可以更深入地了解應用程序在何處查找文件,但似乎并非如此。/proc/self/fd/2/etc/php/7.3/fpm/pool.d/www.confcatch_workers_outputyesindex.php如果有幫助的話,權限index.php如下所示:-rw-r--r-- 1 docker www-data 1887 Jun 23 21:13 index.php我目前正在以 www-data 用戶身份運行 nginx,以 www-data 組中的 docker 用戶身份運行 php-fpm。似乎“主腳本未知”錯誤可能是由許多問題引起的,因此任何關于如何深入挖掘以找到有關問題所在的更多線索的提示都會有所幫助。僅供參考,這是我的完整 nginx conf 文件:upstream intranet { server web:8000;}upstream prometheus { server prometheus:9090;}
1 回答

慕娘9325324
TA貢獻1783條經驗 獲得超4個贊
根據 nginx ngx_http_fastcgi_module文檔,$fastcgi_script_name
內部變量包含請求 URI,或者,如果 URI 以斜杠結尾,則請求 URI 帶有由附加到fastcgi_index
其上的指令配置的索引文件名。當你使用
fastcgi_param?SCRIPT_FILENAME?$document_root$fastcgi_script_name;
并收到/snipe-it/script.php
傳入請求,$uri
內部變量等于?/snipe-it/script.php
,$document_root$fastcgi_script_name
內部變量等于/var/www/html/public/
,連接$document_root$fastcgi_script_name
字符串變為/var/www/html/public//snipe-it/script.php
,這顯然會導致文件不存在。你能做的是
????location?~?^/snipe-it/(?<subpath>.*)$?{ ????????alias?/var/www/html/public/; ????????location?~*?\.php$?{ ????????????????????include?fastcgi_params; ????????????fastcgi_pass?unix:/run/php/php7.3-fpm.sock; ????????????fastcgi_index?index.php; ????????????fastcgi_param?SCRIPT_FILENAME?$document_root$subpath; ????????} ????}
root
請注意,當您使用指令而不是 時,不會出現此問題alias
。/var/www/html/public
但是,除非您將目錄重命名為/var/www/html/snipe-it
(而不是可以使用) ,root /var/www/html;
否則這是不可能的。alias /var/www/html/public/;
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消