Nginx proxy_pass to wordpress docker container

cssdockernginxproxypassWordpress

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"

Best Answer

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.

Related Topic