Saturday, December 8, 2012

How to add https to localhost


Use a Self-Signed SSL Certificate with Apache
These instructions will help you generate a generic self-signed certificate, which may be used to provide SSL service for all name-based hosts on your VPS. Please note that self-signed certificates will generate warnings in a visitor's browser; proceed to "Installing a Commercial SSL Certificate" if you need to set up SSL on a domain using a certificate signed by a commercial SSL provider.
Generate a Self-Signed Certificate
At the shell prompt, issue the following commands to enable SSL for Apache and generate a certificate:
a2enmod ssl mkdir /etc/apache2/ssl openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.key
You will be asked for several configuration values. Enter values appropriate for your organization and server, as shown here. This example will create a certificate valid for 365 days; you may wish to increase this value. We've specified the FQDN (fully qualified domain name) of the VPS for the "Common Name" entry, as this certificate will be used for generic SSL service.
Generating a 1024 bit RSA private key ...................................++++++ ..............................++++++ writing new private key to '/etc/apache2/ssl/apache.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:New Jersey Locality Name (eg, city) []:Absecon Organization Name (eg, company) [Internet Widgits Pty Ltd]:SoftwareDev, LLC Organizational Unit Name (eg, section) []:Web Services Common Name (eg, YOUR name) []:archimedes.mydomain.com Email Address []:support@mydomain.com
Configure Apache to use the Self-Signed Certificate
Since SSL name-based virtual hosts are still not supported in /etc/apache2/ports.conf, we'll need to add an entry for a specific IP address on your VPS as follows. You may use a single IP to provide self-signed SSL service for multiple vhosts, and the same IP may also be used for multiple non-SSL vhosts (HTTPS uses port 443, while HTTP uses port 80).
File excerpt:/etc/apache2/ports.conf
NameVirtualHost 12.34.56.78:443
Replace "12.34.56.78" with your Linode's IP address. Next, edit the virtual host configuration files for sites which you would like to enable SSL on. For each virtual host, you must add the following stanza (change the values as appropriate for each site). Note that this example essentially reproduces the configuration for a non-SSL site, with the addition of three lines for SSL.
File excerpt:Apache virtual hosting file

<VirtualHost 12.34.56.78:443> SSLEngine On SSLCertificateFile /etc/apache2/ssl/apache.pem SSLCertificateKeyFile /etc/apache2/ssl/apache.key ServerAdmin info@mydomain.com ServerName www.mydomain.com DocumentRoot /var/www/mydomain.com/public_html/ ErrorLog /var/www/mydomain.com/logs/error.log CustomLog /var/www/mydomain.com/logs/access.log combined </VirtualHost>


Restart Apache:
service apache2 restart
You should now be able to visit your site with SSL enabled (after accepting your browser's warnings about the certificate).

 
http://library.linode.com/web-servers/apache/ssl-guides

https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04

http://askubuntu.com/questions/49196/how-do-i-create-a-self-signed-ssl-certificate

http://ubuntuforums.org/showthread.php?t=953607



Virtual hosts overlap on 443, first has precedence

sudo gedit /etc/apache2/ports.conf

Change it to
 
<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>


http://blog.breidert.net/virtual-hosts-overlap-443-first-has-precendence/




1 comment:

  1. You can also find information related to hosting services on knowledge base, forum, wiki and also in the blog section of Go4hosting.

    ReplyDelete