每次我嘗試通過 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熱心網友回復:
您正在嘗試使用映射到主機上的埠9001來使用其服務名稱連接到容器。
你有兩個選擇:
使用容器
9000在您的 nginx 上游監聽的埠。php:9000使用 將上游轉發到主機
host.docker.internal:9001。獎勵:使用 Unix Socket,但那是另一回事。
當服務共享一個網路并且必須相互通信時,我通常會使用“內部”埠。這樣,您可以將網路流量保持在該網路內。因此,如果您使用 TCP/IP 進行連接,“解決方案 1”將是最好的方法。另外,如果您不需要從 Docker 網路外部進行連接,則不必映射主機上的埠。
所以......這應該作業:
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/net/490287.html
標籤:码头工人 交响乐 nginx windows-subsystem-for-linux fpm
上一篇:如果EasyAdmin中createEntity或updateEntity上的其他值為null,則將值設為null
