Question regarding rewrite from http to https

Hello,

I am using NGINX as an HTTP proxy, and in some cases, I need to rewrite
all requests from http:// to https://
My proxy configuration has two server {} blocks, one with http, and one
with https

So if my sample configuration looks like: (assume proxy server name is
proxy.com)

server
{
listen 80;
location /
{
rewrite ^/(.*)$ https://proxy.com/$1;
}
}

server
{
listen 443;

}

In this case, I think there is a problem with the regex substitution,
because I get a line like:

2008/05/31 15:10:11 [error] 5802#0: *1 rewrite or internal redirection
cycle while processing
https://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.com/”,
client: 192.168.159.1, server: proxy.com, request: “GET / HTTP/1.1”,
host: “proxy.com
2008/05/31 15:10:11 [debug] 5802#0: *1 http finalize request: 500,
https://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.com/?”
2008/05/31 15:10:11 [debug] 5802#0: *1 http special response: 500,
https://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.comhttps://proxy.com/?”
2008/05/31 15:10:11 [debug] 5802#0: *1 http set discard body
2008/05/31 15:10:11 [debug] 5802#0: *1 HTTP/1.1 500 Internal Server
Error
Server: nginx/0.7.1
Date: Sat, 31 May 2008 09:40:11 GMT
Content-Type: text/html
Content-Length: 192
Connection: close

I’ve tested this with nginx 0.7.1

Any help here would be appreciated

Regards,
Mansoor P.

PS: The redirection works when I use http instead of https

rewrite ^/(.*)$ http://proxy.com/$1;

On Wed, Jun 11, 2008 at 04:29:11AM -0700, Mansoor P. wrote:

location /
{
rewrite ^/(.*)$ https://proxy.com/$1;

  • rewrite ^/(.*)$ https://proxy.com/$1;
    
  • rewrite ^/(.*)$ https://proxy.com/$1  redirect;
    

Gracias, Igor – Vielen Dank

Regards,
Mansoor

----- Original Message -----
From: “Igor S.” [email protected]
To: [email protected]
Sent: Wednesday, June 11, 2008 6:31:27 PM GMT +05:30 Chennai, Kolkata,
Mumbai, New Delhi
Subject: Re: question regarding rewrite from http to https

On Wed, Jun 11, 2008 at 04:29:11AM -0700, Mansoor P. wrote:

location /
{
rewrite ^/(.*)$ https://proxy.com/$1;

  • rewrite ^/(.*)$ https://proxy.com/$1;
    
  • rewrite ^/(.*)$ https://proxy.com/$1  redirect;