docker nginx 502错误的网关 [英] docker nginx 502 bad gateway

查看:1053
本文介绍了docker nginx 502错误的网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将nginx.conf和docker-compose.yml的端口号都更改为9001而不是9000.但是,当我运行docker-compose up时,它显示502 Bad Gateway.这是为什么?我是否只能使用端口9000?

I was trying to change the port number in both nginx.conf and docker-compose.yml to 9001 instead 9000. However, when I run docker-compose up, it shows 502 Bad Gateway. Why is that? am I locked to use port 9000 only?

nginx.conf

location /index.php {
      include fastcgi_params;
      fastcgi_connect_timeout 10s;
      fastcgi_read_timeout 10s;
      fastcgi_buffers 256 4k;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass php:9000; <-- Changing this to 9001
  }

docker-compose.yml

php:
  build: images/php
  volumes:
    - ./images/php/app:/app
  working_dir: /app/public
  command: php-fpm
  links:
    - db
    - cache
  ports:
    - "9000:9000" <-- Changing this to "9001:9001"

推荐答案

您已经更改了Docker正在发布的端口,并且端口Nginx正在将其中继到PHP-FPM,但是您尚未更改端口PHP-FPM.听着.端口9001上没有任何响应Nginx请求的内容,因此没有502.

You've changed the port Docker is publishing, and the port Nginx is relaying to PHP-FPM, but you haven't changed the port PHP-FPM is listening on. There's nothing on port 9001 to respond to the Nginx request, hence the 502.

如果要执行此操作,请更改php-fpm.conf文件中的listen选项:

If you want to do this, alter the listen option in your php-fpm.conf file:

listen = 127.0.0.1:9001

但是您实际上并不需要.如果您希望该服务在端口9001上公开可用,则可以在容器内部将其保留在端口9000上进行监听,而只需更改发布:

But you don't actually need to. If you want the service available on port 9001 publicly, you can leave it listening on port 9000 internally in the container and just change the publishing:

ports:
  - "9001:9000"

这会将9000端口从容器发布到主机上的9001端口,因此您可以在外部使用9001端口.

That will publish port 9000 from the container to port 9001 on the host, so you can use port 9001 externally.

这篇关于docker nginx 502错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆