每次我嘗試通過 localhost:8000 / 127.0.0.1:8000 訪問 nginx 時,我都會遇到此錯誤:
nginx_1 | 2022/05/29 13:28:57 [錯誤] 32#32: *1 connect() 在連接到上游時失敗(111:連接被拒絕),客戶端:172.22.0.1,服務器:,請求:“GET /favicon. ico HTTP/1.1”,上游:“fastcgi://172.22.0.5:9001”,主機:“localhost:8000”,參考者:“http://localhost:8000/”
這個 docker 配置作業的前一天
我創建了github repo以便于代碼審查
我已經嘗試過的:
- 更改 FPM/Nginx 埠
- 重啟 WSL/Docker/PC
- 新的 symfony 專案
- 在同一個網路中添加 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;
uj5u.com熱心網友回復:
You are trying to use the port mapped on your host 9001 to connect to a container using its services name.
You have two options:
Use the port that the container is listening on
9000in your nginx upstream.php:9000Forward the upstream to the host with
host.docker.internal:9001.Bonus: use a Unix Socket, but that is a different ball game.
When services share a network and have to communicate with each other, I would usually use the "internal" port. This way, you keep the network traffic within that network. So "solution 1" would be the best approach if you are using TCP/IP to connect. Plus, if you don't need to connect from outside the Docker network, you don't have to map the port on your host.
So... this should work:
upstream php-upstream {
server php:9000;
}
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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/483367.html
標籤:码头工人 交响乐 nginx windows-subsystem-for-linux fpm
上一篇:MPAndroidChartLineChart每個值旁邊沒有文字
下一篇:如何在Go中模擬“fmap”?
