語境
我已經將這兩個 docker 容器連接到網路:
- php:8-fpm-alpine 與我的網路應用程式,暴露埠 9000。
- nginx:alpine 為應用程式提供服務。
兩個容器都可以訪問包含應用程式檔案的本地目錄。
我的 NGINX 配置:
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
問題
嘗試訪問該站點時,瀏覽器顯示“找不到檔案。”。
NGINX 容器日志:
從上游讀取回應標頭時在標準錯誤中發送的 FastCGI:“主腳本未知”
PHP-FPM 容器日志:
“獲取 /index.php”404
我檢查過的東西
- 應用程式正在運行。
- NGINX 配置中的root實際上指向應用程式檔案的位置。
- 應用程式容器內的應用程式目錄至少一直具有公共讀取和執行權限,這應該排除訪問問題......對嗎?
- There is no other container in the network blocking port 9000.
Could you please point me in some direction? I'm lost.
uj5u.com熱心網友回復:
NGINX 容器可以看到檔案存在于/usr/share/nginx/html/index.php否則該try_files陳述句將生成 404 回應而不是 PHP-FPM。
因此 PHP-FPM 容器已收到SCRIPT_FILENAME設定為的請求,/usr/share/nginx/html/index.php但 PHP 無法使用該路徑名查看檔案。
正如您的評論所證實的,這是兩個容器之間路徑名路由的差異。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444527.html
上一篇:MacM12021上Docker內的Xdebug無法正常作業
下一篇:將確切的環境變數從主機轉發到容器
