Apache2: How to host apps at different ports with SSL?

8,012

Apache Httpd, like most servers, doesn't support using the same port for two different protocols (HTTP and SSL/TLS here).

Doing so would require the server to be able to detect the protocol based on the content of the initial request: whether it's looks like an HTTP request or if it's an SSL/TLS Client Hello message. Some servers can do this (e.g. Grizzly in Java), but this is very unusual. Apache Httpd doesn't support this.

(As a side note, you'd be better off making sure that your users expect to use HTTPS anyway, since HTTP -> HTTPS redirections are only partly useful anyway.)

Share:
8,012

Related videos on Youtube

Aleksandr Makov
Author by

Aleksandr Makov

Updated on September 18, 2022

Comments

  • Aleksandr Makov
    Aleksandr Makov over 1 year

    I'm trying to achieve quite simple task actually.

    I bind application to a port, I enable SSLEngine at each VirtualHost entry for that port. Everything works beside one thing: if you type url that starts with HTTP://, not HTTPS://, you get the Bad Request error hinting you to use HTTPS:// request scheme. So the real question is how to redirect (302) from http://sub.domain.tld:4000/ to https://sub.domain.tld:4000?

    Example seen there: http://isil.monsternett.no:8443

    Thanks.

    Edit:

    Maybe I'm making mistake in core structure? This is what I use:

    Listen 4000
    NameVirtualHost 0.0.0.0:4000
    
    
    <VirtualHost 0.0.0.0:4000>
        RewriteEngine On
        ...
    </VirtualHost>
    
    
    Listen 4001
    NameVirtualHost 0.0.0.0:4001
    
    <VirtualHost 0.0.0.0:4001>
        RewriteEngine On
        ...
    </VirtualHost>
    
    
    Listen N
    NameVirtualHost 0.0.0.0:N
    
    
    <VirtualHost 0.0.0.0:N>
        RewriteEngine On
        ...
    </VirtualHost>
    
  • Aleksandr Makov
    Aleksandr Makov almost 12 years
    Thank you. Yes, the issue is very much like esthetic. Thank you for comprehensive answer.