How to NGINX Solution for Apache ProxyPassReverse


When managing web servers, it's common to encounter the need to reverse proxy through different web servers. Apache's mod_proxy module offers ProxyPass and ProxyPassReverse directives to handle these tasks. However, NGINX can be used as an alternative to Apache for reverse proxy needs due to its performance and configuration simplicity. This article explores how to use NGINX to achieve similar functionality to Apache's ProxyPassReverse.

NGINX Solution for Apache ProxyPassReverse

Understanding Apache’s ProxyPassReverse

The ProxyPassReverse directive in Apache adjusts the URLs in the HTTP headers sent from a reverse proxy. This is essential for maintaining session consistency when the backend server redirects responses.

Apache configure

<VirtualHost myhost:8888>
    ServerName myhost
    DocumentRoot /path/to/myapp/public
    ProxyPass / http://myapp:8080/
    ProxyPassReverse / http://myapp:8080/

Configuring NGINX as a Reverse Proxy

Nginx not have ProxyPassReverse. Therefore a few missing HTTP header. Solve problem Nginx for Apache ProxyPassReverse as below:
server {
    listen 80;
    location /home {
    proxy_set_header Host $host;
        proxy_pass http://IP_Apache:8888;
    location /app {
    proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://IP_TOMCAT:8080;

Testing Your Configuration

After configuring, always restart NGINX and test your setup to ensure that everything works as expected:

sudo systemctl restart nginx

Use curl or visit your domain from a browser to check the behavior of the reverse proxy setup. 


Using NGINX as an alternative to Apache's ProxyPassReverse can offer improved performance and flexibility. By following the steps outlined above, you can set up NGINX to handle reverse proxy tasks efficiently and transparently. This setup not only enhances your server management but also leverages NGINX's robust capabilities for a smooth and scalable web architecture. thank you for reading the page!


Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6