Wordpress+Apache Reverse Proxy

I am deploying a WordPress container to a VPS with CloudLinux, the problem is that I cannot remove the port from the URL therefore the WordPress installer shows me an error, I am using a reverse Apache proxy. I share the configuration:

docker-compose.yml

version: '3.1'

services:

   wordpress:
     image: wordpress:php8.2-apache
     restart: always
     ports:
       - 8088:80
     environment:
       WORDPRESS_DB_HOST: db
       WORDPRESS_DB_USER: {user}
       WORDPRESS_DB_PASSWORD: {password}
       WORDPRESS_DB_NAME: {dbname}
     volumes:
       - {path}:/var/www/html

   DB:
     image: mysql:5.7
     restart: always
     environment:
       MYSQL_DATABASE: {database}
       MYSQL_USER: {user}
       MYSQL_PASSWORD: {password}
       MYSQL_RANDOM_ROOT_PASSWORD: '1'
     volumes:
       - db:/var/lib/mysql

volumes:
   wordpress:
   DB:

app.conf

ServerName domain

      ProxyPass /dir/ http://domain:8088/
      ProxyPassReverse /dir/ http://domain:8088/

      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteRule ^/dir(/.*)?$ https://domain/dir$1 [R=301,L]

The error is that if I enter the URL it does not show me the subdirectory. It redirects me to the main domain with the following syntax: https://domain:8088/wp-admin/install.php and it should be https://domain/dir/wp-admin/install.php

On the other hand, I have a question, if that WordPress was already installed on the VPS, why is the installer opening? Assuming that files were copied from the directory to the container.

Would you like us to guess that error? :slight_smile: Please share all the information that can help people who try to help you.

Depends on the installer. If any file or database entry is missing or incorrect it could show you the installer.

Of course, sorry, Iā€™m new. The error is that if I enter the URL it does not show me the subdirectory. It redirects me to the main domain with the following syntax: https://domain:8088/wp-admin/install.php and it should be https://domain/dir/wp-admin/install.php

There is probably host url configuration in the workdpress config or in the database. Since it was long ago that I used Wordpress, someone on a Wordpress forum can give you a better answer probably regarding where you can find such a configuration.

I already checked the database and the URL is well defined. I think the problem is rather docker with Apache, thank you for taking the time to respond.

I see. Wouldnā€™t it be easier to put the rewrite rule to document root? At least just for testing if that works. Apache HTTPD configuration is also something I havenā€™t done recently, but I if I remember correctly, RewriteRule works differently when you try it in the Apache config. Iā€™m not sure, it is possible that /dir matches the server root.

When I had these kind of problems I made a RewriteRule like this:

RewriteRule ^(/.*)?$ https://example.org/$1 [R=301,L]

which could always redirect to the example site apending the source path to the URL so you know what was wrong.

I tried but it stopped pointing at the container. Possibly you can change the .htaccess configuration rules but I donā€™t know a little about the subject.

It would be just copying that 3 lines to an .htaccess file in the documen root which is no as obvious when there is an .htaccess there already with other rules, but my singleline rule that I suggested for debugging was for using it in the app.conf.

It didnā€™t work :frowning: Iā€™ll keep checking, thanks for your support.

Your app.conf is incomplete/probably wrong.

Which VirtualHost is it for? (You need one for port 80, redirecting to HTTPS, and one for port 443)

You have mod_proxy routing /dir to http://domain:8088/ and mod_rewrite routing /dir to https://domain/dir ā€” only one of those is going to take effect, and in my experience mixing mod_proxy and mod_rewrite, itā€™s never the one Iā€™d expect!

I think your app.conf should be:

<VirtualHost *:80>
  ServerName domain
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/dir(/.*)?$ https://domain/dir$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
  ServerName domain
  ProxyPass /dir/ http://domain:8088/
  ProxyPassReverse /dir/ http://domain:8088/
  ## Plus of course, your certificate definitions
</VirtualHost>

Also, do you really want http://domain:8088/? Now youā€™re routing onto the Internet, where I wouldnā€™t be wanting to expose port 8088. More likely, it should be http://localhost:8088/

Nowā€¦ if your Apache is also containerized and in the same docker network, you could NOT expose the WP port at all, and make the ProxyPass statement ProxyPass /dir http://WP_CONTAINER_NAME/

1 Like