Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active March 21, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niraj-shah/35a1fa990dadbee40b382d8a7a50f2fe to your computer and use it in GitHub Desktop.
Save niraj-shah/35a1fa990dadbee40b382d8a7a50f2fe to your computer and use it in GitHub Desktop.
Apache2 vhost and site config setup. `mydomain-ssl.conf` is the SSL site conf, `mydomain.conf` is the regular site conf, and `mydomain.vhost` is the vhost found in `/etc/apache2/conf/vhosts`.
<IfModule mod_ssl.c>
<VirtualHost *:443>
Include conf/vhosts/mydomain.vhost
SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<VirtualHost *:80>
Include conf/vhosts/mydomain.vhost
</VirtualHost>
ServerAdmin admin@mydomain.com
ServerName mydomain.com
UseCanonicalName on
ServerAlias www.mydomain.com
DocumentRoot /var/www/
<Directory />
Options +FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www >
Options -Indexes
Require all granted
</Directory>
RewriteEngine On
# force non-www
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# force https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment