使用nginx代理的Docker不能工作,它被重定向到一个内部主机上

问题描述 投票:0回答:1

我有一个容器结构,主要是通过一个主容器从外部访问,nginx作为反向代理。

问题是,当我试图进入一个子文件夹时,它会将我重定向到一个内部的网址,例如。

如果我试图访问"http:/php.example.com"工作正常,但如果我尝试访问"http:/php.example.comusers。",然后它把我转到"http:/php_container"这是我的容器在php中的名称。

我的docker-compose.yml如下。

version: '2.1'

networks:
  custom_network:

services:

  reverse_proxy:
    container_name: proxy_container
    image: nginx:1.17.9
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./config/nginx:/etc/nginx
    networks:
      - custom_network
    command: nginx -g 'daemon off;'


  php:
    container_name: php_container
    image: php:7.4.4-apache
    volumes:
      - "./app/php:/var/www/html"
    networks:
      - custom_network

我在nginx中的配置如下。

server {

  listen 80;

  server_name php.example.com;

  location / {
    proxy_pass         http://php_container:80;
    proxy_redirect     off;
  }

}

server {

  listen 443;

  server_name php.example.com;

  location / {
    proxy_pass          http://php_container:443;
    proxy_redirect      off;
  }

}

我希望得到任何帮助,先谢谢你。

docker nginx docker-compose reverse-proxy docker-machine
1个回答
0
投票

我记得你应该使用服务名,而不是容器名,所以在配置文件中进行更改 http:/php_container:80。;到 http:/php:80;

© www.soinside.com 2019 - 2024. All rights reserved.