我正在嘗試在 docker-compose 中運行 nginx 和 php。我能夠構建容器,當我在瀏覽器中瀏覽到一個 html 檔案時,nginx 會為它提供服務。但是當我嘗試瀏覽一個 php 檔案時,我只會得到 502 Bad Gateway。
我知道這可能與我的 nginx 組態檔中的服務器名稱有關,因為我從中獲得的教程提到這需要是正確的。但我嘗試將其更改為“localhost”和“ip-of-my-dockerhost”,結果相同。
我也知道我應該查看日志檔案。但是我有點像 linux 新手。當我打開 Portainer 時,轉到名為 Web 的容器并執行一個 shell,如果我去:
cd /var/log/nginx ; ls
我看到兩個名為 access.log 和 error.log 的檔案
但是,如果我輸入
cat error.log
沒發生什么事!我得到一個新的空白行,游標閃爍,從不輸出任何內容。然后外殼被“凍結”,直到我按 CTRL-C 來終止任務。
docker-compose.yml 的內容
version: "3.7"
#############################
#
# NETWORKS
#
#############################
networks:
main:
external:
name: main
default:
driver: bridge
###########################
#
# SERVICES
#
###########################
services:
# All services / apps go below this line
portainer:
container_name: Portainer
image: portainer/portainer:latest
restart: unless-stopped
command: -H unix:///var/run/docker.sock
networks:
- main
ports:
- "$PORTAINER_PORT:9000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- $DATADIR/portainer:/data # Change to local directory if you want to save/transfer config locally
environment:
- TZ=$TZ
<<snip as don't believe relevant - a bunch of other containers here such as influxdb, radarr etc>>
web:
container_name: Web
image: nginx:latest
networks:
- main
ports:
- 81:80
environment:
- PUID=$PUID
- PGID=$PGID
volumes:
- $CONFIGDIR/nginx/site.conf:/etc/nginx/conf.d/default.conf
- $DATADIR/nginx/code:/code
php:
container_name: php
image: php:7-fpm
networks:
- main
ports:
- 9090:9000
environment:
- PUID=$PUID
- PGID=$PGID
volumes:
- $CONFIGDIR/nginx/site.conf:/etc/nginx/conf.d/default.conf
- $DATADIR/nginx/code:/code
$CONFIGDIR/nginx/site.conf 的內容
server {
index index.php index.html;
server_name 192.168.1.7; ## This is the IP address of my docker host but I've also tried 'localhost' and 'php-docker.local'
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass php:9090;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
uj5u.com熱心網友回復:
9090 是一個暴露的埠。這意味著您可以訪問 localhost:9090 來訪問 PHP 容器,但不能訪問內部容器通信。
更改您的 site.conf:
fastcgi_pass php:9090; => fastcgi_pass php:9000;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/472763.html
