How can I host two different sites on my Linode, one being served over HTTP and the other over HTTPS?

Linode Staff

I need to host 2 sites on the same server - 1 https and one http. Can you send me any links on how to setup using SNI? From what I have been reading I thought that SNI was just for a server with 2x SSL enabled sites - if that's not the case and it can solve the problem then perfect!

2 Replies

Hello,

While I am not 100% familiar with all of the in's and out's of SNI, I am aware that it is primarily used for hosting multiple HTTPS websites on the same IP address.

https://wiki.zimbra.com/wiki/Multiple_SSL_Certificates,_Server_Name_Indication_(SNI)_for_HTTPS

To achieve the configuration that you're looking for you should be able to just use ServerBlocks in Nginx or VirtualHosts in Apache and specify the particular Server_names and Root locations.

In an Nginx application you would need to edit your ServerBlock located at the directory below by default:

 /etc/nginx/conf.d/example.com.conf

You would need to configure this fine to be similar to the one below:

 server {
     listen         80 default_server;
     listen         [::]:80 default_server;
     server_name    example1.com www.example1.com;
     root           /var/www/example1.com;
     index          index.html;
 }

 server {
     listen              443 ssl;
     listen          [::]:443 ssl;
     server_name          example2.com www.example2.com;
     ssl_certificate          www.example2.com.crt;
     ssl_certificate_key        example2.com  www.example2.com.key;
     ssl_protocols          TLSv1 TLSv1.1 TLSv1.2;
     ssl_ciphers          HIGH:!aNULL:!MD5;
     root          /var/www/example2.com;
     index          index.html;
 }

This should cause all requests directed to www.example1.com to connect to your web server over port 80 and serve the content in /var/www/example1.com/index.html and all request directed to www.example2.com to connect to your web server over port 443 using the assigned SSL certificate and serve the content listed in /var/www/example2.com/index.html.

You can view more information on Nginx and configuring Nginx server blocks in the documentation below:

https://www.linode.com/docs/web-servers/nginx/how-to-configure-nginx/#server-blocks
https://nginx.org/en/docs/http/configuring_https_servers.html
https://www.nginx.com/resources/wiki/start/topics/examples/server_blocks/
https://www.itworld.com/article/2987967/data-center/why-your-nginx-server-is-responding-with-content-from-the-wrong-site.html

The configuration on an Apache server is actually pretty similar but some of the verbiage is different. First and foremost Apache does not use Server Blocks it uses the VirtualHosts file. This file is usually located in the directory:

 /etc/apache2/sites-available/example.com.conf

You would want to implement a configuration similar to the one below:

  <VirtualHost *:80>
      ServerAdmin      webmaster@example.com
      ServerName      example.com
      ServerAlias      www.example.com
      DocumentRoot      /var/www/example.com/public_html/
      ErrorLog      /var/www/example.com/logs/example1-error.log
      CustomLog      /var/www/example.com/logs/example1-access.log combined
 </VirtualHost>

 <VirtualHost *:443>
      SSLEngine on
      SSLCipherSuite $sslcipherinfo
      SSLCertificateFile      /etc/ssl/example2.com.crt
      SSLCertificateKeyFile   /etc/ssl/example2.com.key

      ServerAdmin      webmaster@example.com
      ServerName      example2.com
      ServerAlias      www.example.com
      DocumentRoot    /var/www/example2.com/public_html/
      ErrorLog        /var/www/example2.com/logs/example2-error.log
      CustomLog       /var/www/example2.com/logs/example2-access.log combined

 </VirtualHost>

You can view more information on Apache and configuring VirtualHosts in the documentation below:

https://www.linode.com/docs/web-servers/apache/apache-web-server-on-ubuntu-14-04/
https://wiki.apache.org/httpd/NameBasedSSLVHosts
https://httpd.apache.org/docs/2.4/vhosts/examples.html
https://stackoverflow.com/questions/9126851/same-server-both-ssl-and-non-ssl

Feel free to let us know if you have any issues with the information in this post or any other questions.

Thanks,
Matt Watts
Linode Support Team

You should use HTTPS unless you have a really good reason not to.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct