Http->https redirection on the same port

Hi, I’m currently migrating from Apache to lighttpd, but ran into a
blocker that I can’t seem to find my way around. So I’m looking into
using nginx instead, but I wanted to ask if my blocker exists here as
well.

I have a web application running on a high port number. It needs to
be SSL encrypted, but I need to redirect the browser to https:// URLs
automatically if they leave it as standard HTTP. For instance:

http://my.app:8000https://my.app:8000

I can’t use different port numbers. Apache supports this quite well,
and while supposedly lighttpd supports this in its most recent
version, I’ve been having some really weird problems I’ve been
tracking down.

Does anyone know if this is possible with nginx? I’ll make the switch
in a second if it is. Thanks.

On Tue, Jun 17, 2008 at 08:55:35AM -0700, Michael Nachbaur wrote:

I can’t use different port numbers. Apache supports this quite well,
and while supposedly lighttpd supports this in its most recent
version, I’ve been having some really weird problems I’ve been
tracking down.

Does anyone know if this is possible with nginx? I’ll make the switch
in a second if it is. Thanks.

     server {
         listen  8000;

         ssl     on;
         #other ssl stuff

         error_page  497   https://my.app:8000$request_uri;

         ...
     }

The 497 code means that a usual request was sent to HTTPS.

BTW, how had you implemented this in Apache ?

On 17-Jun-08, at 9:11 AM, Igor S. wrote:

The 497 code means that a usual request was sent to HTTPS.

Is it possible to do this in such a way that I don’t have to encode
the hostname in the configuration file? We would like to redirect
requests to the original name our host was talked to with, e.g.
http://1.2.3.4:8000
should redirect to https://1.2.3.4:8000, whereas http://my.app:8000
should redirect to https://my.app:8000.

BTW, how had you implemented this in Apache ?

We built this with an ugly CGI script that handled the redirection. I
can’t remember off the top of my head how this is built, because it
was written before my time. Lighttpd supports a “$HOST[scheme]”
variable that can be used to handle request configuration, but it
seems to be buggy.

On 18-Jun-08, at 1:21 PM, Igor S. wrote:

variable that can be used to handle request configuration, but it
seems to be buggy.

I had asked because last time I checked this, Apache simply returned
400
for a plain HTTP request sent to a HTTPS server. I’m curious how do
you pass the request to CGI script ?

Well, we listed the error handler for 400 errors as being /cgi-bin/
400.cgi which outputted a redirect page containing meta refresh to the
new URL.

On Wed, Jun 18, 2008 at 01:05:26PM -0700, Michael Nachbaur wrote:

be SSL encrypted, but I need to redirect the browser to https:// URLs
switch

}

The 497 code means that a usual request was sent to HTTPS.

Is it possible to do this in such a way that I don’t have to encode
the hostname in the configuration file? We would like to redirect
requests to the original name our host was talked to with, e.g.
http://1.2.3.4:8000 should redirect to https://1.2.3.4:8000, whereas
http://my.app:8000 should redirect to https://my.app:8000.

  error_page  497   https://$http_host:8000$request_uri;

BTW, how had you implemented this in Apache ?

We built this with an ugly CGI script that handled the redirection. I
can’t remember off the top of my head how this is built, because it
was written before my time. Lighttpd supports a “$HOST[scheme]”
variable that can be used to handle request configuration, but it
seems to be buggy.

I had asked because last time I checked this, Apache simply returned 400
for a plain HTTP request sent to a HTTPS server. I’m curious how do
you pass the request to CGI script ?

On Wed, Jun 18, 2008 at 01:53:28PM -0700, Michael Nachbaur wrote:

can’t remember off the top of my head how this is built, because it
400.cgi which outputted a redirect page containing meta refresh to the
new URL.

But where do you know host name ? AFAIK Apache does not preserve it.