0

I am trying to setup a Ubuntu 16.04 machine such that an nginx-proxy container would reverse-proxy to a wordpress container.

The issue I am having is that when trying to access the website from the outside world, nginx only forwards some GET requests, viz. the HTML of the home page and the favicon. It doesn't forward any other requests to load the other elements of the page.

Here is my docker-compose.yml:

version: "2"
services:

 mysql:
  image: mysql:latest
  container_name: db
  restart: always
  environment:
   - MYSQL_ROOT_PASSWORD=SuperSecretMysqlPassword
  volumes:
   - /home/docker-stuff/var-lib-mysql:/var/lib/mysql

 nginx-proxy:
  image: jwilder/nginx-proxy:alpine
  container_name: nginx
  restart: always
  ports:
   - "443:443"
   - "80:80"
  volumes:
   - /var/run/docker.sock:/tmp/docker.sock:ro

 wordpress:
  image: wordpress:latest
  container_name: wp
  restart: always
  environment:
   - VIRTUAL_HOST=example.com
   - WORDPRESS_DB_HOST=mysql
   - WORDPRESS_DB_USER=wordpress
   - WORDPRESS_DB_PASSWORD=SuperSecretWordpressPassword
  volumes:
   - /home/wp/:/var/www/html/

Here is the output from docker-compose up when I try to access the website (on port 80):

nginx          | nginx.1    | 92.222.75.87 172.18.0.1 - - [23/Jun/2017:18:26:20 +0000] "POST /wp-cron.php?doing_wp_cron=1498242380.0386610031127929687500 HTTP/1.1" 503 213 "http://92.222.75.87/wp-cron.php?doing_wp_cron=1498242380.0386610031127929687500" "WordPress/4.8; https://92.222.75.87"
wp             | 172.18.0.3 - - [23/Jun/2017:18:26:19 +0000] "GET / HTTP/1.1" 200 17780 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | example.com 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET / HTTP/1.1" 200 17467 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/images/header.jpg HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/style.css?ver=4.8 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/jquery/jquery.js?ver=1.12.4 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js?ver=1.0 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/global.js?ver=1.0 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js?ver=2.1.2 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/wp-embed.min.js?ver=4.8 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/wp-emoji-release.min.js?ver=4.8 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/images/header.jpg HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js?ver=1.0 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/global.js?ver=1.0 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js?ver=2.1.2 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | 92.222.75.87 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /wp-includes/js/wp-embed.min.js?ver=4.8 HTTP/1.1" 503 213 "http://example.com/" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
wp             | 172.18.0.3 - - [23/Jun/2017:18:26:20 +0000] "GET /favicon.ico HTTP/1.1" 200 192 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"
nginx          | nginx.1    | example.com 146.198.151.82 - - [23/Jun/2017:18:26:20 +0000] "GET /favicon.ico HTTP/1.1" 200 0 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"

All images freshly pulled from docker hub. I tried "jwilder/nginx-proxy:latest" instead of alpine, same results...

I don't know nginx very well, so I would really appreciate some help here... Thanks a lot in advance!

  • Interestingly, I add an owncloud:latest docker image and am redirecting port 80 to it, and this works fine... That's insane! – seeker6 Jun 24 '17 at 16:15
  • When I manually GET the various items of the home page using curl, this is working fine... Could it be that nginx forwards the GET requests too fast for the wordpress container? – seeker6 Jun 26 '17 at 8:14
  • I managed to run tcpdump inside the wordpress container, and I can confirm I am seeing only the GET requests for / and the favicon. – seeker6 Jun 26 '17 at 8:30
  • OK, I managed to run tcpdump inside the nginx-proxy container, and I can see that nginx replies "503 Service Temporarily Unavailable" to my browser. I ran wireshark on my desktop, and I can indeed see those 503 responses. It looks like the browser decompress the gzipped home page (which is somewhat large), and start querying the other elements while http response for the page is still ongoing... Maybe that's the issue... – seeker6 Jun 26 '17 at 9:45
0

After a lot of debugging, I found the root cause of this problem. I am detailing it here in the hope that it will help other people.

The issue was that the links in the home page were built from the IP address of the host, and not the host name itself. This caused the browser to issue GET requests with a "Host:" header set to the IP address instead of the host name, and obviously nginx didn't know what to do with that (and the request was then handled by the additional server section in nginx.tmpl which issues 503 responses for all requests).

Why did the wordpress home page had those IP addresses in the links? That's probably because I initially installed wordpress by accessing the server using the IP address directly, when I the DNS was not up and running yet. I deleted the wordpress database and re-installed it by accessing the server by its host name, and voila! Everything works like a charm!

For some reason, wordpress saves the host name you use to access it and uses that to build its html...

  • In a docker I am running nginx proxy along with lets encrypt nginx companion. I have installed wordpress. My Nginx forwards request on 443 and also shows https. But how do i make it communicate with apache so that wordpress starts?? – Surendra Patil Mar 8 '18 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.