• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to configure Apache Reverse Proxy on Rewrite rule on Ubuntu 22.04

  • 00:54 lsb_release -a
  • 01:13 apt install apache2 -y
  • 01:52 ip a
  • 02:24 a2enmod proxy
  • 02:33 a2enmod proxy_http
  • 02:40 a2enmod rewrite
  • 02:57 vim /etc/apache2/sites-enabled/000-default.conf
  • 05:38 vim /etc/apache2/sites-enabled/000-default.conf
{{postValue.id}}

To Configure Apache Reverse Proxy On Rewrite Rule

Introduction

The "Reverse Proxy" rule template provides a mechanism for generating inbound rewrite rules that proxy HTTP requests to an alternate server. Additionally, this template can optionally create an outbound rewrite rule to correct host names in the link URLs within HTML responses. The Apache HTTP Server's mod_rewrite module can be utilized to configure a reverse proxy and manage URL manipulations effectively.

Procedure

Step 1: Check the OS version

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy

Step 2: Install Apache webserver by using apt command

root@linuxhelp:~# apt install apache2 -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libflashrom1 libftdi1-2 libllvm13
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service
Processing triggers for ufw (0.36.1-4ubuntu0.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

Step 3: Apache installed successfully, Then check the system IP address by using following command.

root@linuxhelp:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:0c:1e:e5 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.6.133/23 brd 192.168.7.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::ed65:e6a5:ee5d:b483/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Step 4: Go to the browser and search with the system IP address Snap 1

Step 5: Now enable some modules

root@linuxhelp:~# a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@linuxhelp:~# a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@linuxhelp:~# a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2

Step 6: Then edit the Apache default virtual host file and add some line in the file

root@linuxhelp:~# vim /etc/apache2/sites-enabled/000-default.conf
Add the following lines
RewriteEngine On
RewriteRule ^/old-path/(.*)$ /new-path/$1 [R=301,L]
ProxyPass / http://192.168.6.134:8080/
ProxyPassReverse / http://192.168.6.134:8080/

Step 7: Now restart the Apache2 service to apply changes

root@linuxhelp:~# systemctl restart apache2

Step 8: Go to the browser and search with backend server IP Snap 2

Step 9: Now reload the previous page that we are search with our system IP address. It will redirect to the backend server web page Snap 3

Conclusion :

We have reached the end of this article. In this guide, we have walked you through the steps required to configure Apache Reverse Proxy on Rewrite rule on Ubuntu 22.04. Your feedback is much welcome.

Tags:
matthew
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is a reverse proxy in Apache?

A

A reverse proxy in Apache forwards client requests to another server (backend), masking the backend server's identity while handling requests on behalf of it.

Q

How do I enable Apache reverse proxy?

A

To enable reverse proxy, you need to enable the mod_proxy and mod_proxy_http modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2

Q

What is the purpose of RewriteRule in reverse proxy?

A

RewriteRule is used to modify the incoming URL before it is forwarded to the backend server. This can be used for URL redirection, restructuring URLs, or applying custom routing logic.

Q

How do I add a rewrite rule with reverse proxy?

A

Example configuration:
RewriteEngine On
RewriteRule ^/old-path/(.*)$ /new-path/$1 [R=301,L]
ProxyPass /app http://backend-server:8080/
ProxyPassReverse /app http://backend-server:8080/

Q

How do I troubleshoot reverse proxy and rewrite issues?

A

Check Apache's error logs (/var/log/apache2/error.log), ensure mod_rewrite is enabled, test with curl commands, and verify the backend server's accessibility.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ryan ?
how to use visual traceroute tool

Am using traceroute command to check for the route. i got this tool while surfing. So pls help me out installation and usage of Visual traceroute tool.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.