- Web

Solve the problem that the jump address appears inconsistent with the client’s target address during the reverse proxy of Apache

Abstract

This article aims at solving the problem that the jump address appears inconsistent with the client’s target address during the reverse proxy of Apache, avoiding inaccessible errors due to inconsistent jump addresses.

Problem

Example configuration:

<VirtualHost _default_:443>
    Servername blog.davcloud.top
    SSLEngine on
    SSLCertificateFile ssl_certificate_file
    SSLCertificateKeyFile ssl_certificate_key_file
    RewriteEngine On

    ProxyPass / http://192.168.1.101:3333/
    ProxyPassReverse / http://192.168.1.101:3333/
</VirtualHost>

In this example, proxy server URL on the public network is: https://blog.davcloud.top/, and forward internal server URL is: http://192.168.1.101:3333.

When the input access the address on client is: https://blog.davcloud.top/test.html, the actual access address is: https://192.168.1.101:3333/test.html, which is not exist to the client.

Solution

Add a “ProxyPreserveHost On” command in the configuration.

Configuration:

<VirtualHost _default_:443>
    Servername blog.davcloud.top
    SSLEngine on
    SSLCertificateFile ssl_certificate_file
    SSLCertificateKeyFile ssl_certificate_key_file
    RewriteEngine On

    ProxyPass / http://192.168.1.101:3333/
    ProxyPassReverse / http://192.168.1.101:3333/
    ProxyPreserveHost On
</VirtualHost>

When the input access the address on client is: https://blog.davcloud.top/test.html, the actual access address is: https://blog.davcloud.top/test.html, which is correct for the client.

About Ziqi.Yang394

Read All Posts By Ziqi.Yang394

Leave a Reply

Your email address will not be published. Required fields are marked *