Skip to content

Instantly share code, notes, and snippets.

@czarpino
Last active August 29, 2015 13:56
Show Gist options
  • Save czarpino/8911822 to your computer and use it in GitHub Desktop.
Save czarpino/8911822 to your computer and use it in GitHub Desktop.
Virtual host, HTTPS, SSL/TLS, How to

Windows

Look for httpd.conf and add the following line at the bottom:

IncludeOptional "c:/amp/vhosts/*"

Now, go to c:/amp/vhosts and create a file named vhosts.conf.

> cd c:/amp/vhosts
> cd. > vhosts.conf

Open vhosts.conf in a text editor then add in the following virtual hosts.

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:\\amp\\www"
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com.local
    DocumentRoot "C:\\Path\\to\\project\\public\\directory"
    <Directory />
        AllowOverride all
        Require all granted
    </Directory>
    
    # Redirect all http requests to its https counterpart
	Redirect permanent / https://example.com.local/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com.local
    DocumentRoot "C:\\Path\\to\\project\\public\\directory"
    <Directory />
        AllowOverride all
        Require all granted
    </Directory>

    # Enables HTTPS
    SSLEngine on
    SSLCertificateFile "C:\\Path\\to\\public\\key"
    SSLCertificateKeyFile "C:\\Path\\to\\private\\key"
</VirtualHost>

Also, add in the website domain to the hosts file (C:\Windows\System32\drivers\etc\hosts). Note that modifying this file requires admin rights.

> cd "C:\Windows\System32\drivers\etc"
> notepad hosts

Add in the following line:

127.0.0.1    example.com.local

Finally, restart the Apache webserver and check example.com.local in your browser. If using a self-signed certificate, the browser should intercept the request with a page saying something like "The site's security certificate is not trusted!". Proceed anyway, and done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment