简体   繁体   English

docker nginx 502坏网关

[英]docker nginx 502 bad gateway

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. 我试图将nginx.conf和docker-compose.yml中的端口号更改为9001而不是9000.但是,当我运行docker-compose时,它会显示502 Bad Gateway。 Why is that? 这是为什么? am I locked to use port 9000 only? 我是否只能使用端口9000?

nginx.conf 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 泊坞窗,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"

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. 您已经更改了Docker正在发布的端口,并且端口Nginx正在转发到PHP-FPM,但您还没有更改PHP-FPM正在侦听的端口。 There's nothing on port 9001 to respond to the Nginx request, hence the 502 . 端口9001上没有任何内容可以响应Nginx请求,因此502

If you want to do this, alter the listen option in your php-fpm.conf file: 如果要执行此操作,请更改php-fpm.conf文件中的listen选项:

listen = 127.0.0.1:9001

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: 如果您希望公共端口9001上的服务可用,您可以让它在容器内部监听端口9000,只需更改发布:

ports:
  - "9001:9000"

That will publish port 9000 from the container to port 9001 on the host, so you can use port 9001 externally. 这将从容器将端口9000发布到主机上的端口9001,因此您可以在外部使用端口9001。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM