【发布时间】:2021-05-28 03:54:12
【问题描述】:
我使用 docker 在 VM 中设置了 3 个容器
第一个是托管在端口 5050 上的 WordPress 页面 第二个是托管在端口 5000 上的 PHPMyAdmin 页面 最后一个是托管在 80 端口上的 Nginx 服务器
所有容器都可以正常工作,但我想在端口 80 中设置第三个容器(nginx)以根据路径链接转发所有请求,例如:
localhost/wordpress =forworded to=> WordPress 托管的端口 5050
phpMyAdmin 也一样
这是我目前所做的:default.conf
server {
listen 80;
root /var/www/localhost/htdocs/;
index index.html index.htm index.php;
server_name _;
client_max_body_size 32m;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/lib/nginx/html;
}
location /wordpress{
proxy_pass http://127.0.0.1:5050;
}
location /phpmyadmin{
proxy_pass http://127.0.0.1:5000;
}
}
注意:所有 phpMyadmin 和 WordPress 都在 WordPress 和 PHPMyAdmin 的同一个容器上设置了 Nginx 服务器
【问题讨论】:
-
你能展示三个 Docker 容器的配置吗?另外,什么不起作用?您是否收到特定错误?
-
是的,当我启动三个容器时,它们启动良好,我可以访问所有容器,但使用端口
http://localhost:5050访问 WordPress,但我想使用链接访问它们(Nginx 容器重定向到每个容器)就像我在问题中给出的例子一样。
标签: php wordpress docker nginx portforwarding