doudengshen5591 2016-09-25 17:33
浏览 621

docker nginx 502坏网关

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"
  • 写回答

1条回答 默认 最新

  • duanjia2415 2016-09-26 08:06
    关注

    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.

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

    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:

    ports:
      - "9001:9000"
    

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

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题