【问题标题】:WordPress, Docker and nginxWordPress、Docker 和 nginx
【发布时间】:2014-04-27 02:49:52
【问题描述】:

Ubuntu 服务器 14.04 LTS。我将 WordPress 作为标准安装运行,即在 /var/www/html 中。我还有一个在 Docker 容器中运行的 Discourse 实例,并暴露了 8081 端口。我的意图是在 domain.com 上拥有 WP 实例,在 sub.domain.com 上拥有 Discourse。我尝试使用 nginx 来拦截对 sub.domain.com 的请求,但它似乎不起作用——它只是将所有内容发送到 domain.com。我做错了什么?

/etc/nginx/sites-enabled/sub.domain.com:

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

  location / {
    proxy_pass http://localhost:8081;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  }
}

【问题讨论】:

    标签: php wordpress nginx docker


    【解决方案1】:

    尝试以下方法:

    server {
      listen 80;
      server_name sub.domain.com;
    
      location / {
        proxy_pass http://127.0.0.1:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
      }
    }
    

    localhost 不一定会解析为您的 Docker 容器正在侦听的127.0.0.1

    确保您可以从您的机器访问端口8081。运行:

    $ telnet 127.0.0.1 8081
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    

    【讨论】:

    • 做到了。我在/etc/hosts 中也有一个错误的条目。谢谢!
    • 我可以远程登录到 wordpress,但是当我加载网站时,浏览器被重定向到本地主机
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2020-08-01
    • 2021-08-23
    • 2017-03-27
    • 2017-12-30
    相关资源
    最近更新 更多