Fiko Borizqy
Fiko Borizqy

Follow

Fiko Borizqy

Follow

Apache 2: Setup Reverse Proxy to Access Private Network Over The Internet

Fiko Borizqy's photo
Fiko Borizqy
·Apr 10, 2023·

2 min read

Apache 2: Setup Reverse Proxy to Access Private Network Over The Internet

Photo by Stephen Phillips - Hostreviews.co.uk on Unsplash

Do you already have apache2 configured on your server, and you want to have another application running on the same port as apache have? which is port 80.

We can do it by implementing reverse proxy, so how to do it?

1. Create Virtual Host

We need to create a virtual host, in this case I will try to create magento245.dev.fiko.me

<VirtualHost *:80>
    ServerAdmin hi@fiko.me
    ServerName testing.dev.fiko.me
</VirtualHost>

2. Setup Reverse Proxy

Next we need to place reverse proxy, and point this virtual host to original port you have previously installed on. In this case I already installed my application locally on port of 8082, so I need to point to port of 8082.

<VirtualHost *:80>
    ServerAdmin hi@fiko.me
    ServerName testing.dev.fiko.me

    SSLProxyEngine On
    RequestHeader set Front-End-Https "On"
    ProxyPreserveHost On
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off

    ProxyPass / http://127.0.0.1:8082/
    ProxyPassReverse / http://127.0.0.1:8082/
</VirtualHost>

3. Try to test your apache2 configuration

Try to run :

sudo apache2ctl configtest

it should have Syntax Ok response.

Once it's good, restart your apache

sudo service apache2 restart

and try to access your application from browser.

4. Install Required Modules (Optional)

Do you face this error?

It's too general, but maybe you haven't enabled required apache2 modules, you need to enable these modules:

sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http

Then restart your apache2, and refresh the browser.


References:

Did you find this article valuable?

Support Fiko Borizqy by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this