Home > Backend Development > PHP Tutorial > Docker nginx multiple domain name configuration issues

Docker nginx multiple domain name configuration issues

WBOY
Release: 2023-03-03 10:10:02
Original
2133 people have browsed it

尝试配置dockers官方nginx镜像nginx.conf配置失败,对其所知甚少基本靠找教程。
以下是我尝试的流程:
YBa

<code>docker run -d   --name YBa --restart=always  -v /Storage/Volumes/App/YBa:/usr/src/myapp php
</code>
Copy after login
Copy after login

YBb

<code>docker run -d   --name YBa --restart=always  -v /Storage/Volumes/App/YBb:/usr/src/myapp php
</code>
Copy after login
Copy after login

Nginx

<code>docker run -d -p 80:80 --name Nginx  --link YBa:yba  --link YBb:ybb  -v /Storage/Volumes/Services/Nginx/Conf/nginx.conf/nginx.conf:/etc/nginx/nginx.conf:ro --restart=always nginx</code>
Copy after login
Copy after login

Nginx.conf

<code>    user nobody nogroup;
events { 

  worker_connections 512; 
}
http { 

  upstream yba {
    server yba; 

  }
  upstream ybb {
    server ybb; 

  }
  server {
    listen *:80; 

    server_name http://app1.com; 
    location / { 

      proxy_pass http://yba/; 

      proxy_set_header   X-Real_IP $remote_addr;
      proxy_set_header   Host      $http_host;
    }
    
  }
}
  server {
    listen *:80; 

    server_name http://app2.com; 
    location / { 

      proxy_pass http://ybb/; 

      proxy_set_header   X-Real_IP $remote_addr;
      proxy_set_header   Host      $http_host;
    }
    
  }
} 
         </code>
Copy after login
Copy after login

现在问题是如何通过单个配置文件完成多个域指向多个容器的问题
想了解还有没有其他的解决方法
如何针对单容器的不同子目录多个主域名指向

回复内容:

尝试配置dockers官方nginx镜像nginx.conf配置失败,对其所知甚少基本靠找教程。
以下是我尝试的流程:
YBa

<code>docker run -d   --name YBa --restart=always  -v /Storage/Volumes/App/YBa:/usr/src/myapp php
</code>
Copy after login
Copy after login

YBb

<code>docker run -d   --name YBa --restart=always  -v /Storage/Volumes/App/YBb:/usr/src/myapp php
</code>
Copy after login
Copy after login

Nginx

<code>docker run -d -p 80:80 --name Nginx  --link YBa:yba  --link YBb:ybb  -v /Storage/Volumes/Services/Nginx/Conf/nginx.conf/nginx.conf:/etc/nginx/nginx.conf:ro --restart=always nginx</code>
Copy after login
Copy after login

Nginx.conf

<code>    user nobody nogroup;
events { 

  worker_connections 512; 
}
http { 

  upstream yba {
    server yba; 

  }
  upstream ybb {
    server ybb; 

  }
  server {
    listen *:80; 

    server_name http://app1.com; 
    location / { 

      proxy_pass http://yba/; 

      proxy_set_header   X-Real_IP $remote_addr;
      proxy_set_header   Host      $http_host;
    }
    
  }
}
  server {
    listen *:80; 

    server_name http://app2.com; 
    location / { 

      proxy_pass http://ybb/; 

      proxy_set_header   X-Real_IP $remote_addr;
      proxy_set_header   Host      $http_host;
    }
    
  }
} 
         </code>
Copy after login
Copy after login

现在问题是如何通过单个配置文件完成多个域指向多个容器的问题
想了解还有没有其他的解决方法
如何针对单容器的不同子目录多个主域名指向

可以在本地配置好对应的配置文件在conf/上,例conf/api.app2.com.conf,在建立容器时添加进容器, dockerfile 代码如下

<code>From nginx:1.9
MAINTAINER terry.dawu@gmail.com
ADD nginx.conf /etc/nginx/nginx.conf
ADD conf/* /etc/nginx/conf.d/
RUN mkdir /opt/www && mkdir /opt/log
RUN chmod -R 755 /opt/log /opt/www
VOLUME ["/opt"]</code>
Copy after login

  1. Nginx 代理分发,指向本机不同端口

  2. CDN分发,指向服务器不同端口

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template