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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置