大网数据广告活动
服务器运维问答

Nginx proxy_pass to wordpress docker container

· 52CE 我爱测

Hi guys sorry if I'm making a elementary mistake but I am really lost here. I have set up my Ubuntu 16.04 server is Nginx(Not in a docker container, running on host machine) and wordpress(In a docker container). Docker Hub Wordpr…

问题原文

原帖链接 · kawaijoe · CC BY-SA 3.0

Hi guys sorry if I'm making a elementary mistake but I am really lost here.

I have set up my Ubuntu 16.04 server is Nginx(Not in a docker container, running on host machine) and wordpress(In a docker container).

Docker Hub Wordpress repo: (I can't post more then two links but its the official Wordpress repo)

After some configuration, I managed to get nginx running and the wordpress container. When I access the wordpress website through the raw IP address and port it works fine. However, when I do a proxy_pass from nginx to the container, my wordpress website seems to have lost all of its css. Ironically, the page still kinda loads.

Here's an example: (Hyperlink to an image)

http://[IP Address]:51080/wp-admin/install.php

http://example.com/wp-admin/install.php

sites-available

upstream example.com {
    server localhost:51080;
}

server {
    listen  80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:51080;
    }
}

docker run command

docker run --name example.com -d -v /docker/example.com:/var/www/html wordpress

/etc/hosts (I have added the following line to the file)

[IP address] example.com

Thank you for any help!

EDIT:

  • /var/log/nginx/error.log - is empty (yes, I've checked, it's logging to this file)
  • /var/log/nginx/access.log

Log entry:

<IP Address> - - [11/Mar/2017:11:33:35 -0500] "GET /wp-admin/install.php HTTP/1.1" 200 11144 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

It may help to set some headers so that the upstream knows the correct frontend server name. See this document for more.

For example, I use:

proxy_set_header    Host                $host;
proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
proxy_set_header    X-Forwarded-Proto   $scheme;
proxy_set_header    Accept-Encoding     "";
proxy_set_header    Proxy               "";

Also, check that your HOME and SITEURL settings are correct. See this document for details.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。