0

I'm launching a Docker container for WordPress following this tutorial. I'm running this on a machine that is at my desk, I have complete access. It is running Ubuntu 20.04.

Here is my docker-compose.yml for reference.

version: '3.3'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: rootpassword
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: dbpassword

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "12130:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: dbpassword
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

(Passwords replaced)

When I run docker-compose up -d, the container comes up, the server is available at 127.0.0.1:12130, and I can configure and install WordPress. Everything works fine from the machine hosting the application.

When I try to access the site from a different device, the blog loads, but there are no styles. I expect that this is because the "Site Address" is configured as http://127.0.0.1:12130, so when the browser tries to fetch the stylesheet, it's going there, which 404s.

I believe the solution here is to configure nginx to give the application a public address and change the "Site Address" and "WordPress Address" to that address. Once I do that, the entire service is completely inaccessible by any means. I have to destroy the data with docker-compose down --volumes and install from scratch.

For reference, here is my complete /etc/nginx/conf.d/default.conf, I stripped everything else out. I also stopped all of my other web services, so just WordPress is running.

ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;

server {
    listen 443 ssl;
    server_name sub.mydomain.org;

    location / {
        proxy_pass http://127.0.0.1:12130;
    }
}

If I try to access https://sub.mydomain.org using Firefox, it redirects me to 127.0.0.1 (no port) and gives me the standard "Unable to connect" page. If I curl https://sub.mydomain.org, it exits with no output and no errors. I get the same error using 127.0.0.1:12130 and localhost:12130 directly, they both just redirect me to 127.0.0.1, no port, and fail to connect or return empty.

At this point, if I wait a few minutes, accessing 127.0.0.1:12130 or https://sub.mydomain.org in Firefox causes the page to infinitely reload. This is repeatable, I have done this process several times in making sure I have my information straight. For the first few minutes it just redirects to 127.0.0.1 and dies, then it starts infinitely reloading without me changing any config files or restarting any services.

One final note. If I turn on nginx before changing the "Site Address" setting, I can access the server from outside my network just fine, but as before, the styles don't load. So nginx is doing something. And it's been working fine for the other servers I'm hosting.

What's going on here?

Why can I not access the server after I change "Site Address" and "WordPress Address"?

  • Am I going down the complete wrong path by trying to modify the "Site Address" and "WordPress Address" settings?
  • If I should modify those, why is the server behaving like this?
    • Is my nginx configuration wrong?
    • Is my WordPress configuration wrong?
    • Is something else wrong?
  • Or is it something completely different?

I'm very new to self hosting, I apologize if there is an an obvious solution that I'm not seeing. Thank you for your patience.

TechnoSam
  • 131
  • 3
  • You can't use 127.0.0.1/localhost to access the site externally. – AlexD Feb 08 '21 at 11:24
  • @AlexD Yes, I understand that. I never tried to do that. I only made one reference to connecting externally, which did work because I used the server's LAN address. That's the not problem. The problem is that after setting the "Site Address", I cannot access it all, locally or externally. – TechnoSam Feb 08 '21 at 14:35
  • You say above that you configured your "Site Address" as "http://127.0.0.1:12130". This means that WordPress will automatically redirect you to that address, 127.0.0.1 and it won't work if you attempting to access the site externally. Also, you didn't specify what is the address sub.mydomain.org resolves to. If it is 127.0.0.1 then you have the same problem. – AlexD Feb 08 '21 at 15:59
  • No, I didn't say that. I said that it *defaults* to localhost. I specifically say that I changed it to sub.mydomain.org. And my DNS is set up correctly, I've tested that. It works for other applications, and I even specifically mentioned that I *can* access the site outside my network before changing "Site Address" externally, using the domain name. I appreciate your time, but I'm quite certain the problem lies elsewhere. Is there anything else you would check to figure out why the site becomes inaccessible after changing the Site Address? – TechnoSam Feb 08 '21 at 17:56

1 Answers1

0

It turns out that I needed to set some headers in my nginx config. This post helped me discover that.

Now my config looks like this.

server {
    listen 443 ssl;
    server_name sub.domain.org;

    location / {
        proxy_pass http://127.0.0.1:12130;
        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               "";
    }
}

After setting the "Site Address" and "WordPress Address", everything seems to be working.

I would like to do some more research to understand exactly what's happening here and why it's necessary. If anyone wants to explain in the comments I'd be grateful.

TechnoSam
  • 131
  • 3