Snippets tagged "apache server" Snippets tagged "apache server"

Redirect HTTP -> HTTPS requests in a VirtualHost

<VirtualHost 100.101.102.103:80>
 
  ServerName    subdomain.domain.tld
  DocumentRoot  /path/to/docroot
 
  <IfModule mod_rewrite.c>
    RewriteEngine   on
    RewriteLog      /var/log/apache2/https_rewrite.log
    RewriteLogLevel 1
    RewriteCond     %{SERVER_PORT} !^443$
    RewriteCond     %{SERVER_NAME} ^subdomain.domain.tld$
    RewriteRule     ^/(.*) https://%{SERVER_NAME}/$1 [L,R]
  </IfModule>
 
</VirtualHost>
 
<VirtualHost 100.101.102.103:443>
 
  ServerName    subdomain.domain.tld
  DocumentRoot  /path/to/docroot
 
  SSLEngine On
  SSLCertificateFile     /etc/apache2/ssl_conf/myservicename.crt
  SSLCertificateKeyFile  /etc/apache2/ssl_conf/myservicename.key
 
 
</VirtualHost>
by Nicolas Perriault on 2006-12-19, tagged apache  http  https  server  sysadmin