Custom port for HTTPS/SSL on Ubuntu


Enable SSL

sudo a2enmod ssl

Add new Apache site

  • declare new port: in /etc/apache2/ports.conf, after <IfModule mod_ssl.c>, add
Listen 9001
  • create SSL version of your site
cd /etc/apache2/sites-available
cp toto toto-ssl
  • in toto-ssl change
<VirtualHost *:9000>


<VirtualHost *:9001>
  • in toto-ssl, add before </VirtualHost>
	SSLEngine on
	SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
	SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

	<FilesMatch "\.(cgi|shtml|phtml|php)$">
		SSLOptions +StdEnvVars
	<Directory /usr/lib/cgi-bin>
		SSLOptions +StdEnvVars

	BrowserMatch "MSIE [2-6]" \
		nokeepalive ssl-unclean-shutdown \
		downgrade-1.0 force-response-1.0
	# MSIE 7 and newer should be able to use keepalive
	BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  • enable your SSL site
sudo a2ensite toto-ssl
  • restart Apache
sudo /etc/init.d/apache2 restart


  • lines added to toto-ssl come from default-ssl (default SSL Apache site on port 443)