【问题标题】:how to redirect port 80 to another port如何将端口80重定向到另一个端口
【发布时间】: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


【解决方案1】:

你需要在末尾添加/

location /wordpress{
          proxy_pass  http://127.0.0.1:5050/;  
}
location /phpmyadmin{
          proxy_pass  http://127.0.0.1:5000/;  
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2012-01-22
    • 2017-05-15
    相关资源
    最近更新 更多