skip to Main Content

I have two docker containers (one for mysql and the other for wordpress). it looks like this.

enter image description here

I would like to link my domain (example.com) to the wordpress container. So far, I came up with this apache config file.

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
    ServerAlias www.example.com
    ProxyRequests off
<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>
<Location />
        ProxyPass http://localhost:4568/
        ProxyPassReverse http://localhost:4568/
</Location>
</VirtualHost>

Now, example.com works just fine for the home page but when I try to go to directory (say, http://example.com/product/asdasd) it redirects me to http://localhost/product/asdasd.

I have tried changing localhost in the config file with the domain name but it doesn’t work;

ProxyPass http://example.com:4568/
ProxyPassReverse http://example.com:4568/

Can anyone help me to figure out what is the right config file to do so?

Thnx

2

Answers


  1. To use example.com:4568, you need to expose port 4568 publicly OR
    you can set entry in /etc/hosts as
    localhost:4568 example.com
    to keep it private

    Login or Signup to reply.
  2. I reproduced and just made it work.

    You need to add these lines in your wp-config.php:

    define('WP_HOME', 'http://www.example.com/');
    define('WP_SITEURL', 'http://www.example.com/'); `
    

    This is the apache config file for my example.com domain:

    <VirtualHost *:80>
      <Proxy *>
        Order deny,allow
        Allow from all
      </Proxy>
      ProxyPreserveHost On
      RequestHeader set X-Forwarded-Proto "http"
      ProxyPass / http://localhost:4568/
      ProxyPassReverse / http://localhost:4568/
      <Location />
        Order allow,deny
        Allow from all
      </Location>
    </VirtualHost>
    

    After these changes, WP immediately stopped redirecting to localhost:

    enter image description here

    If you still face any problems, leave a comment and I’ll try to update the post with the other changes that I performed on my apache configs, although those should not be relevant.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search