我在 docker-compose 中將 Nginx 作為服務運行,并在容器內的 /app 上安裝了一個卷。
我只是將整個專案結構從 Linux 復制到運行良好的 MacOS。
這是我的 docker-compose.yml:
version: '3'
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
- ./app:/app
sass:
image: larryprice/sass
volumes:
- ./app/public/assets:/src
php:
build:
context: .
dockerfile: ./docker/php/PHP.Dockerfile
volumes:
- ./app:/app
我有一個 PHP 應用程式的簡單配置,但 location 中的 root 指令似乎被忽略了。我不明白為什么。
conf.d 目錄中的單個組態檔:
server {
listen 80 default_server;
root /app/public;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
嘗試訪問http://localhost/index.php時失敗
172.19.0.1 - - [16/Oct/2021:11:22:28 0000] "GET /index.php HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36" "-"
2021/10/16 11:22:28 [error] 26#26: *1 open() "/usr/share/nginx/html/index.php" failed (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET /index.php HTTP/1.1", host: "localhost"
因此,它默認查找 in /usr/share/nginx/html/,但有location一個 uri匹配。
誰能解釋一下?非常感謝!
uj5u.com熱心網友回復:
在設定fastcgi_params可能會覆寫您的SCRIPT_FILENAMEPARAM,你可以嘗試移動fastcgi_param SCRIPT_FILENAME后include fastcgi_params
server {
listen 80 default_server;
root /app/public;
index index.php index.html index.htm;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
uj5u.com熱心網友回復:
專案結構來自這個資源:https : //www.sitepoint.com/docker-php-development-environment/
而不是僅僅從 Linux 復制專案結構(正如我在一個問題中提到的),我依次按照本教程手動添加這些指令,令人驚訝的是它開始正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323896.html
標籤:php 码头工人 nginx docker-compose
上一篇:如何使用混合分隔符(即方括號、空格和雙引號)來決議日志(nginxaccess.log)?并可選擇轉換為json
