# Reverse proxy and html rewrite

**URL:** <https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144>\
**Category:** NGINX\
**Created:** [October 7, 2010, 1:45pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144 "2010-10-07T13:45:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 7, 2010, 1:45pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/1 "2010-10-07T13:45:56Z")

</div>

Hi there,

I’d like to know if nginx supports html rewrite when configured as a  
reverse proxy.

My problem is that the site I’d like to RP set the full server URL in  
the login form to force the login in HTTPS, ie sth like:

....

While, for the browser, it accesses the site with  
[http://localhost:2080](http://localhost:2080) or [https://localhost:2443](https://localhost:2443)

Is there a way to configure nginx to take this into account ?

Thanks & regards,  
Manuel

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 8, 2010, 1:58pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/2 "2010-10-08T13:58:06Z")

</div>

Hi

As far as I know body content rewriting it’s not possible with nginx, I  
may be wrong, i’m a newbie with nginx.  
What nginx supports is URL rewriting through HttpRewrite module and this  
has nothing to do with returned body content rewriting.

URL Rewriting works when nginx receives a requests, it parses the URL  
requested and rewrite as appropiate according to your rules. At this  
point the call have not been made to the real request. It doesn’t matter  
where the real call (after rewriting is done) is then sent, be it  
reverse proxy, static, fcgi daemon, whatever you want.

What do you want is to rewrite the content that the backends returns,  
that’s not something you can do with the HttpRewrite module.

What indeed you can do to solve your problem is to setup nginx to accept  
ssl connections for that site, let the login form send users to ssl and  
inside ssl server config in nginx place a 301 redirect to your http  
server.

Cheers

Guzman

Posted at Nginx Forum:

> **[Re: Reverse proxy and html rewrite](https://forum.nginx.org/read.php?2,138048,138451#msg-138451)**
>
> Hi there, I'd like to know if nginx supports html rewrite when configured as a reverse proxy. My problem is that the site I'd like to RP set the full server URL in the login form to force the login in HTTPS, ie sth like: \<form...

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 8, 2010, 4:03pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/3 "2010-10-08T16:03:58Z")

</div>

On 8 Out 2010 12h56 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi
> 
> As far as I know body content rewriting it’s not possible with  
> nginx, I may be wrong, i’m a newbie with nginx. What nginx supports  
> is URL rewriting through HttpRewrite module and this has nothing to  
> do with returned body content rewriting.

It can: [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpSubModule)

And there’s a third party module that does more elaborate replacements:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Of course nginx must “own” those locations where content rewriting is  
to be done.

— appa

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 8, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/4 "2010-10-08T16:14:30Z")

</div>

On 8 Out 2010 14h58 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> And there’s a third party module that does more elaborate  
> replacements:
> 
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpSubModule)  
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxHttpSubsModule)

— appa

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 8, 2010, 4:21pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/5 "2010-10-08T16:21:32Z")

</div>

Sweet! Every day I love nginx more!

Do you know if it add too much load on it to check every returned html  
content?

Whenever this module allow regular expressions (right now says there it  
accepts only variables) and allow to redirect user on match to another  
page,  
this would be a nice replacement for apache2 mod\_security body parse  
feature.

Thanks for the info, as I said I’m still a newbie with nginx 🙂

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [October 14, 2010, 11:14am UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/6 "2010-10-14T11:14:58Z")

</div>

Ok thanks all for the links & proposal.

Cheers,  
Manuel

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [January 6, 2011, 5:06am UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/7 "2011-01-06T05:06:15Z")

</div>

I actually have this working with httpsubmodule, but it doesn’t seem to  
rewrite any files that are .php, .aspx. Only .html files, is this an  
Nginx issue?

Posted at Nginx Forum:

> **[Re: Reverse proxy and html rewrite](https://forum.nginx.org/read.php?2,138048,163976#msg-163976)**
>
> Hi there, I'd like to know if nginx supports html rewrite when configured as a reverse proxy. My problem is that the site I'd like to RP set the full server URL in the login form to force the login in HTTPS, ie sth like: \<form...

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [January 6, 2011, 6:05am UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/8 "2011-01-06T06:05:18Z")

</div>

its to do with gzip, ive seen the same thing when the backend gzip  
encodes.

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [January 16, 2011, 10:37pm UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/9 "2011-01-16T22:37:54Z")

</div>

Hello,

You have to disable GZip on the backend web servers: Apache and IIS.

Olivier

Posted at Nginx Forum:

> **[Re: Reverse proxy and html rewrite](https://forum.nginx.org/read.php?2,138048,166792#msg-166792)**
>
> Hi there, I'd like to know if nginx supports html rewrite when configured as a reverse proxy. My problem is that the site I'd like to RP set the full server URL in the login form to force the login in HTTPS, ie sth like: \<form...

---

<div class="post-metadata">

**Author:** ![Manuel\_Vacelet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/aeb1de/32.png) [@Manuel\_Vacelet](https://www.ruby-forum.com/u/Manuel_Vacelet)\
**Post date:** [January 6, 2011, 6:16am UTC](https://www.ruby-forum.com/t/reverse-proxy-and-html-rewrite/196144/10 "2011-01-06T06:16:35Z")

</div>

How can you disable the Gzip? Would it be on NGINX or the web servers?  
The web server serving up PHP is apache 2 and ASPX is IIS 7

Posted at Nginx Forum:

> **[Re: Reverse proxy and html rewrite](https://forum.nginx.org/read.php?2,138048,163995#msg-163995)**
>
> Hi there, I'd like to know if nginx supports html rewrite when configured as a reverse proxy. My problem is that the site I'd like to RP set the full server URL in the login form to force the login in HTTPS, ie sth like: \<form...
