gpt4 book ai didi

php - 从Docker容器访问Nginx时出现502错误的网关

转载 作者:行者123 更新时间:2023-12-02 19:14:36 25 4
gpt4 key购买 nike

我正在尝试在我的docker容器中创建一个php
但是,当我在浏览器上转到localhost时,会不断收到502错误的网关。
错误日志显示
[error] 11#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: (my IP), server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
我的nginx conf看起来像这样

server {
listen 80;
server_name jenkins.local;
root /var/www/html;
index index.php;
access_log /var/log/nginx/localhost-access.log;
error_log /var/log/nginx/localhost-error.log;

location / {

try_files $uri $uri/ /index.php?$args;

}

location ~ \.php$ {

try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;

}

}
我是docker和PHP的新手,所以如果需要提供其他信息,请告诉我。

最佳答案

您开始php-fpm吗?
9000端口开放吗?
简短版

 upstream websocketserver {
server localhost:8080;
}

server {
listen 80;
server_name jenkins.local; //Or try localhost;
root /var/www/html;
index index.php;

access_log /var/log/nginx/localhost-access.log;
error_log /var/log/nginx/localhost-error.log;

location / {

proxy_pass http://websocketserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 86400; # neccessary to avoid websocket timeout disconnect
proxy_send_timeout 900s;
proxy_redirect off;

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock; //Check if your php is 7.4, run php -v

}

}

关于php - 从Docker容器访问Nginx时出现502错误的网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64189071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com