使用 docker 部署 nginx 和 PHP 遇到 502 报错
问题:
我在使用docker
部署php
环境, 访问 .php
文件时,报502
错误。
目前的现状:
- 访问
.php
后缀的文件,均报502
错误,并有以下错误日志connect() failed (111: Connection refused) while connecting to upstream
- 访问
.html
后缀的文件, 正常输出页面 - 在启动的
php
容器里,执行php index.php
, 正常输出内容
我的环境和执行脚本:
docker-compose.yml
services : php: image: 'php:7.2.5-fpm' container_name: php volumes: - ~/nginx/www:/www - ~/nginx/php-db.sh:/nginx/php-db.sh tty: true ports: - "9000:9000" entrypoint: - /bin/bash - /nginx/php-db.sh networks: - laravel nginx: image: 'nginx' container_name: nginx ports: - "80:80" volumes: - ~/nginx/www:/usr/share/nginx/html - ~/nginx/conf.d:/etc/nginx/conf.d depends_on: - php networks: - laravel networks: laravel:
nginx 相关的配置文件
server { listen 80; server_name api.laravel.test; root /usr/share/nginx/html/app/public; index index.php index.html index.htm; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico {access_log off; log_not_found off;} location = /robots.txt {access_log off; log_not_found off;} error_page 404 /index.php; location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/app/public/$fastcgi_script_name; include fastcgi_params; } location ~/\.(?!well-know).*{ deny all; } }
求助:
希望有了解的朋友,可以给我一些思路和排查方法
推荐文章: