Monday, April 20, 2020

How to Configure Apache Reverse Proxy on CentOS

Description: Here I have explained what is Apache Reverse Proxy and How to configure it.

What is Reverse Proxy: 
A reverse proxy accepts connections and then routes them to an appropriate path.

For example, if we have any application running on port 5000, we can configure a reverse proxy to accept connections on HTTP or HTTPS, which can then transparently proxy requests to the application backend.

Configure Reverse Proxy.
  1. Verify Proxy module using below command
# httpd -M

Output


proxy_module (shared)


lbmethod_byrequests_module (shared)


proxy_balancer_module (shared)


proxy_http_module (shared


      2. Configure Virtual Host as follow: [We’ll use example application running on 127.0.0.1:5000 as the backend service that we want to reverse proxy requests to]

 


<VirtualHost *:443>


        # The ServerName directive sets the request scheme, hostname and port that


        # the server uses to identify itself. This is used when creating


        # redirection URLs. In the context of virtual hosts, the ServerName


        # specifies what hostname must appear in the request's Host: header to


        # match this virtual host. For the default virtual host (this file) this


        # value is not decisive as it is used as a last resort host regardless.


        # However, you must set it for any further virtual host explicitly.


        #ServerName www.example.com


        ProxyPreserveHost On


        ProxyPass /api http://127.0.0.1:5000


        ProxyPassReverse /api http://127.0.0.1:5000


         ServerAdmin webmaster@localhost


        ServerName app1.demo.com


        ServerAlias app1.demo.com


        DocumentRoot /var/www/html/demoapp


SSLEngine on


SSLCertificateFile /var/www/html/certs/demo.crt


SSLCertificateKeyFile /var/www/html/certs/demo.key


SSLCertificateChainFile /var/www/html/certs/demo_CA.crt




        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,


        # error, crit, alert, emerg.


        # It is also possible to configure the loglevel for particular


        # modules, e.g.


        #LogLevel info ssl:warn




        ErrorLog ${APACHE_LOG_DIR}/error.log


        CustomLog ${APACHE_LOG_DIR}/access.log combined




        # For most configuration files from conf-available/, which are


        # enabled or disabled at a global level, it is possible to


        # include a line for only one particular virtual host. For example the


        # following line enables the CGI configuration for this host only


        # after it has been globally disabled with "a2disconf".


        #Include conf-available/serve-cgi-bin.conf


</VirtualHost>


  • Restart httpd service and verify. 
# systemctl start httpd

No comments:

Post a Comment