每次我尝试通过localhost:8000/127.0.0.1:8000访问nginx时,我都会遇到以下错误:
nginx_1|2022年5月29日13:28:57 [错误] 32编号32:* 1个连接()失败(111:连接被拒绝),客户端:www.example.com,服务器:,请求:172.22.0.1"快速目录名称://172. 22. 0. 5:9001",主机:"本地主机:8000",引用地址:"网址:http://localhost:8000/" "localhost:8000", referrer: "http://localhost:8000/"
在这个码头配置生效的前一天
我为创建了github repo,以便于代码评审
我已经试过了:
1.更改FPM/Nginx端口
1.重启WSL/Docker/PC
1.新symfony项目
1.在同一网络中添加php && nginx容器
对接-组合:
version: '3.7'
services:
database:
image: postgres:11-alpine
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: symfony
POSTGRES_DB: main
ports:
- 15432:5432
php:
build: ./docker/php
ports: ['9001:9000']
volumes: ['./symfony/:/var/www/symfony:cached']
depends_on:
- database
nginx:
build: ./docker/nginx
ports: ['8000:80']
volumes: ['./symfony/:/var/www/symfony:cached']
adminer:
image: adminer
restart: always
links:
- database
ports:
- 8081:8080
symfony.conf:
upstream php-upstream {
server php:9001;
}
server {
listen 80;
root /var/www/symfony/public;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
nginx.conf:
user nobody;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 4000;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_min_length 10240;
gzip_comp_level 1;
gzip_vary on;
gzip_disable msie6;
gzip_proxied expired no-cache no-store private auth;
gzip_types
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
application/atom+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
reset_timedout_connection on;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
client_body_temp_path /tmp 1 2;
client_body_buffer_size 256k;
client_body_in_file_only off;
}
daemon off;
2条答案
按热度按时间mcvgt66p1#
您正在尝试使用主机
9001
上Map的端口连接到使用其服务名称的容器。您有两种选择:
1.使用容器在nginx上游中的
9000
上侦听的端口。php:9000
1.使用
host.docker.internal:9001
将上游转发到主机。1.额外的好处:使用Unix套接字,但这是一个不同的球游戏。
当服务共享一个网络并且必须相互通信时,我通常使用"内部"端口。这样,您可以将网络流量保持在该网络内。因此,如果您使用TCP/IP连接,"解决方案1"将是最佳方法。另外,如果您不需要从Docker网络外部连接,则不必Map主机上的端口。
所以...这个应该行
daolsyd02#
我也遇到过同样的问题,只是因为我用的是
CMD
或者ENTRYPOINT
;它们都阻止PHP-FPM正常工作。