gpt4 book ai didi

wordpress - 如何使用Nginx前端通过两个Docker容器运行的两个wordpress网站。

转载 作者:行者123 更新时间:2023-12-02 20:22:26 25 4
gpt4 key购买 nike

我有两个wordpress实例,每个实例作为一个docker容器运行。我想通过单个nginx服务器前端/代理这两个wordpress实例。

以下是我的nginx配置文件。

upstream docker-site1 {
server site1_site;
}

upstream docker-site2 {
server site2_site;
}

server {
listen 80;
server_name myserver.domain.com;

proxy_set_header Host "myserver.domain.com"; # required for Docker client sake
proxy_set_header X-Real-IP $remote_addr; #pass on real client IP
client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads
# required to avoid HTTP 411: see issue #1486 (https://github.com/dotcloud/docker/issues/1486)
chunked_transfer_encoding on;

location /site2 {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/pass/.site1_htpasswd;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_pass http://docker-site2/;

}

location / {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/pass/.site1_htpasswd;
proxy_set_header Host $http_host;
add_header HTTP_HOST $http_host;
proxy_pass http://docker-site1;
proxy_http_version 1.1;
}
}

最佳答案

有一个nginx代理镜像可以自动代理您的容器。您可以找到它here。像这样运行代理:

$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

然后,您必须使用环境变量运行wordpress图片
$docker run -e VIRTUAL_HOST=foo.bar.com ...
$docker run -e VIRTUAL_HOST=bar.foo.com ...

或者,更好的是,在您的Dockerfile中添加ENV指令并公开端口
# My Wordpress 1 Dockerfile
ENV VIRTUAL_HOST=foo.bar.com
EXPOSE 80

关于wordpress - 如何使用Nginx前端通过两个Docker容器运行的两个wordpress网站。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37019024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com