Home Apache virtual host basic template
Post
Cancel

Apache virtual host basic template

This is where I start when I have to configure an Apache server: a simple virtual host template with ssl rewrite.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<VirtualHost *:80>

    ServerName my.domain.com
    ServerAlias my.domain.com
    
    RewriteEngine On
    RewriteCond %{HTTPS} =off
    RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
    
</VirtualHost>

<VirtualHost *:443>

    DocumentRoot "/path/to/htdocs"
    
    ServerName my.domain.com
    ServerAlias my.domain.com
    
    SSLEngine on
    
    SSLCertificateFile /path/to/ssl/files/ssl_certificate.crt
    SSLCertificateKeyFile /path/to/ssl/files/privatekey.pem
    SSLCertificateChainFile /path/to/ssl/files/IntermediateCA.crt
    
    DirectoryIndex index.html
    
    ErrorLog "|/path/to/bin/rotatelogs -l '/path/error_%Y-%m-%d.log' 86400"
    CustomLog "|/path/to/bin/rotatelogs -l '/path/access_%Y-%m-%d.log' 86400" common
    
</VirtualHost>
This post is licensed under CC BY 4.0 by the author.