Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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>
share|improve this question

migrated from stackoverflow.com May 28 '12 at 10:19

This question came from our site for professional and enthusiast programmers.

    
Thanks for the tip! –  Aleksandr Makov May 27 '12 at 19:41
add comment

2 Answers 2

up vote 1 down vote accepted

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|improve this answer
    
Thank you. Yes, the issue is very much like esthetic. Thank you for comprehensive answer. –  Aleksandr Makov May 28 '12 at 13:37
add comment

If your web page is hosted on port 9001, just enable any port on your linux box and make these changes in /etc/httpd/conf.d/ssl.conf. Then, set your listen port to 9002 and create your SSL certificate and key and put the following configuration in your httpd.conf file:

Listen 9001
<VirtualHost *:9001>
ServerAdmin root@localhost
DocumentRoot /mnt/work/httpd
<Directory "/mnt/work/httpd">
Options FollowSymLinks
 AllowOverride AuthConfig
</Directory>
  SSLEngine On
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateKeyFile /etc/httpd/www.test.example.com.key
SSLCertificateFile /etc/httpd/www.test.example.com.crt
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.test.example.com:9002%{REQUEST_URI}  

And your .htaccess file should look like this:

AuthType Digest
AuthName "realm"
AuthDigestProvider file
AuthGroupFile /dev/null
AuthUserFile /mnt/work/httpd/digest_auth
Require user username
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.