How we use apache as a reverse proxy?

Recently, I had the situation to handle one of the WordPress based websites.

In one of the new changes, due to the environment dependency the shared code not worked in our server machine. So we had planned to solve the issue with the help of docker components.

When we do that, the new landing page changes should not affect our existing website flows. So we made a decision to make some changes in the apache config file to configure the reverse proxy. But it was not easy as it easy sounds.

Proxy Config

Online references suggested ProxyPass, ProxyPassReverse directives.

<Location “/TargetURL/”>

ProxyPass “http://localhost:1234/forwardURL/"

ProxyPassReverse “http://localhost:1234/forwardURL/"

Order allow,deny

Allow from all

</Location>

Resource Mapping Issue

When we did that the page loaded without the dependent resource files. So we have checked for the solution and came up with the suggestion of adding another two directives- ProxyPreserveHost, ProxyRequests in the config file.

<VirtualHost *:80>

ProxyPreserveHost On

ProxyRequests Off

DocumentRoot “/XXX/XXX/XX/XX/X”

ServerName “XXXX.XX”

……………………………..

WordPress Pages routings

Now the page worked without errors, but WordPress configured pages and URLs not worked. We felt fed up and stopped at this point, we took a break. And again started to analyze the issue and finally, we found that we missed the .htaccess file in the docker container. it was a silly mistake it took 4 hours to figure it out.

I was new to the apache and PHP environment, but it was a great learning experience and worth trying it.

If you like this post, kindly share a clap 👏 or some thoughts 💬 with me!.

--

--