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.

4
  • You can't use 127.0.0.1/localhost to access the site externally. Commented Feb 8, 2021 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. Commented Feb 8, 2021 at 14:35
  • You say above that you configured your "Site Address" as "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. Commented Feb 8, 2021 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? Commented Feb 8, 2021 at 17:56

2 Answers 2

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.

0

I had a similar problem. Thanks to your post I found a solution which seems easier - at least for me. If you don't want to use nginx at all you can also just configure your local IP address as "Site Address" in wordpress.

In my case:

Wordpress Address: http://192.168.178.21:12130

Site Address http://192.168.178.21:12130

That already solves the problem, meaning you will be able to access your wordpress website using e.g 192.168.178.21:12130 in a browser on all machines in the network - The site will load correctly - no 404.

But yes, if your IP changes you have to adapt that address. In that case your approach might be more suitable.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Feb 17, 2024 at 8:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.