douyong1850 2017-12-25 15:03
浏览 141
已采纳

Docker for Windows和Symfony 4中的NGINX 502错误网关错误

I'm trying to set up Symfony 3 in Docker on a Windows machine with NGINX and PHP-FPM. At the moment, I get a 502 bad gateway error. I changed the FPM port from 9000 to 8000 because on my host, port 9000 is already in use by a hyper-v service vmms.exe. I don't know if it's related.

docker-compose.yml

version: "3"

services:

  nginx:
      build: ./nginx
      volumes:
        - ./symfony:/usr/shared/nginx/html
      ports:
        - "80:80"
        - "443:443"
      environment:
        - NGINX_HOST=free-energy.org
      depends_on:
        - fpm

  fpm:
      image: php:fpm
      ports:
          - "8000:8000"
      # It seems like FPM receives the full path from NGINX
      # and tries to find the files in this dock, so it must
      # be the same as nginx.root
      volumes:
          - ./symfony:/usr/shared/nginx/html

Dockerfile NGINX:

FROM nginx:1.13.7-alpine

# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/

EXPOSE 80
EXPOSE 443

default.conf override NGINX:

server {
    listen  80;
    server_name free-energy.org;

    # this path MUST be exactly as docker-compose.fpm.volumes,
    # even if it doesn't exist in this dock.
    root /usr/share/nginx/html;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/.+\.php(/|$) {
        fastcgi_pass fpm:8000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
  • 写回答

3条回答 默认 最新

  • dongxue7306 2017-12-25 17:20
    关注

    Could you please check php-fpm container? As I remember, the php-fpm default port is 9000, not 8000. Change port mapping from inside container from 8000 to 9000

      ports:
          - "8000:9000"
    

    Or if it already to use on your host you can expose the port only between containers.

      expose:
          - "9000"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!