http->https redirection on the same port

Michael Nachbaur mike at
Thu Jun 19 00:05:26 MSD 2008

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

> On Tue, Jun 17, 2008 at 08:55:35AM -0700, Michael Nachbaur wrote:
>> 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:
>> ->
>> 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$request_uri;
>             ...
>         }
> 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. 
  should redirect to, whereas  
should redirect to

> 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.

More information about the nginx mailing list