How to set up SSL on Linux VM?

Danyal Sheikh 26 Reputation points
2020-08-30T13:15:02.823+00:00

Hi,

I have a PHP MySQL app which I migrated to Azure. I created a Linux vm, installed LAMP stack and successfully deployed the app on newly created vm. Now I want to secure this vm with ssl. I have the 443 port open but I can't figure out how to enable ssl on linux vm. I also looked into the possibility of adding a Lets Encrypt cert to my vm but for some reason I cannot see "Custom Domains" or "SSl/TLS" options in my resource group. Can someone please help me and point in the right direction?

Thanks,
Danyal

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,196 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
0 comments No comments
{count} votes

Accepted answer
  1. thgibard-MSFT 356 Reputation points
    2020-08-30T16:17:08.837+00:00

    Hello,

    What you're wanting to setup is not an Azure configuration. You've just created a IaaS VM, it's a classical website. So, the only step you need is to configure your Network Security Group (related to VM) to open the port 443. Once you've done this, you will need to configure your Web Server (Apache or whatever) to support https. You can use a true certificate or a Let's encrypt one.

    Here : https://www.linode.com/docs/security/ssl/ssl-apache2-debian-ubuntu/ you have an exemple on how to configure https/ssl on a classical Linux virtual machine.

    Or here : https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04 you've the version for Let's Encrypt.

    2 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. John Britto 0 Reputation points
    2023-04-08T13:30:25.88+00:00

    To enable SSL on your Linux VM, you need to install and configure an SSL certificate. Here's a general outline of the steps you need to take: Obtain an SSL certificate: You can either purchase an SSL certificate from a trusted third-party vendor or use a free SSL certificate from Let's Encrypt. Since you mentioned that you can't see the SSL/TLS option in your Azure resource group, you may need to manually install the Let's Encrypt cert on your VM. Install the SSL certificate on your VM: The exact steps for installing the SSL certificate will depend on the type of certificate you obtain. Generally, you'll need to copy the certificate files to your server and update your Apache configuration to use the certificate. Here's a guide on how to install a Let's Encrypt certificate on Rocky Linux / CentOS / RHEL / Fedora: https://www.linuxteck.com/secure-apache-with-sssl-in-rocky-linux/. Update your Apache configuration: Once the SSL certificate is installed, you'll need to update your Apache configuration to use HTTPS instead of HTTP. This typically involves updating your virtual host configuration file to specify the SSL certificate and key files, as well as redirecting all HTTP traffic to HTTPS. Verify that SSL is working: Finally, you should verify that SSL is working by accessing your website via HTTPS and checking that the SSL certificate is valid. If you encounter any issues during these steps, you may need to consult the documentation for your specific Linux distribution, web server, or SSL certificate provider. Good luck!

    0 comments No comments

  2. ajkuma 22,521 Reputation points Microsoft Employee
    2020-08-31T08:45:20.433+00:00

    @Arbab Danyal , As thgibard’s mentioned, on an Azure Virtual Machine, you would typically perform the exact same steps/process as you would on-premise; for app configuration (/adding SSL certificate).

    Just to highlight for additional info, Azure offers several ways to host websites/apps: Azure App Service WebApps (PAAS solution), Virtual Machines (IAAS), Service Fabric, Azure Storage (for static website) and Azure Static Web Apps.

    Based on your requirement, you can use the same SSL certificate (you purchased) on an Azure VM and the process GoDaddy mentioned is correct.
    Please refer this document for step-step instructions Tutorial: Secure a web server on a Linux virtual machine in Azure with TLS/SSL certificates stored in Key Vault - Esp. Prepare and generate certificate sections.

    1.You can take a look at the step-step instructions outlined in the above document, which involves the following steps:

    • Create an Azure Key Vault
    • Generate or upload a certificate to the Key Vault
    • Create a VM and install the NGINX web server
    • Inject the certificate into the VM and configure NGINX with a TLS binding

    2.Just sharing as additional information only and from your issue description about [TLS/SSL] option – It is available on Azure App Service (In your case -the website is deployed on Azure VM).

    Only in case if you are interested to use App Service Certificate - You can create App Service Certificate and export a PFX copy of it and use it for other Azure services (Example Azure Virtual Machine) or outside of Azure. So, essentially the following is the process:

    • To configure TLS for an application, you first need to get a TLS/SSL certificate that has been signed by a Certificate Authority (CA), a trusted third party who issues certificates for this purpose. If you do not already have one, you need to obtain one from a company that sells TLS/SSL certificates.
    • Your application must be configured to use the certificate, and an HTTPS endpoint must be added.
    • Upload the certificate and then you could access the webapp using HTTPs.

    Configure App Service Certificate to Azure Virtual machines (on IIS)
    import-a-certificate-from-key-vault

    Hope this helps! Kindly let us know if you have any further questions, we are happy to help.

    1 person found this answer helpful.

  3. Weily 86 Reputation points
    2020-10-03T04:34:10.183+00:00

    I. Apache: Creating Your CSR with OpenSSL

    Use the instructions in this section to create your own shell commands to generate your Apache CSR with OpenSSL.

    Recommended: Save yourself some time. Use the DigiCert OpenSSL CSR Wizard to generate an OpenSSL command to create your Apache CSR. Just fill out the form, click Generate, and then paste your customized OpenSSL command into your terminal.

    How to Generate a CSR for Apache Using OpenSSL

    If you prefer to build your own shell commands to generate your Apache CSR, follow the instructions below.

    Log in to your server via your terminal client (ssh).

    Run Command

    At the prompt, type the following command:

    Note: Make sure to replace server with the name of your server.

    openssl req –new –newkey rsa:2048 –nodes –keyout server.key –out server.csr

    Generate Files

    You've now started the process for generating the following two files:

    Private-Key File: Used to generate the CSR and later to secure and verify connections using the certificate.

    Certificate Signing Request (CSR) file: Used to order your SSL certificate and later to encrypt messages that only its corresponding private key can decrypt.

    When prompted for the Common Name (domain name), type the fully qualified domain (FQDN) for the site that you are going to secure.

    Note: If you're generating an Apache CSR for a Wildcard certificate, make sure your common name starts with an asterisk (e.g., *.example.com).

    When prompted, type your organizational information, beginning with your geographic information.

    Note: You may have already set up default information.

    Now, your OpenSSL .csr file is created.

    Order Your SSL/TLS Certificate

    Open the .csr file you created with a text editor.

    Copy the text, including the -----BEGIN NEW CERTIFICATE REQUEST----- and -----END NEW CERTIFICATE REQUEST----- tags, and paste it in to the DigiCert order form.

    Save Private Key

    Save (back up) the generated .key file. You need it later to install your SSL certificate.

    Install Certificate

    After you've received your SSL certificate from DigiCert, you can install it on your server.

    II. Apache: Installing & Configuring Your SSL Certificate

    If you still need to create a certificate signing request (CSR) and order your certificate, see Apache: Creating Your CSR with OpenSSL.

    After we've validated and issued your SSL certificate, you can install it on your Apache server (where the CSR was generated) and configure the server to use the certificate.

    How to Install and Configure Your SSL Certificate on Your Apache Server

    Copy the certificate files to your server.

    Log in to your DigiCert account and download the intermediate (DigiCertCA.crt) and your primary certificate (your_domain_name.crt) files.

    Copy these files, along with the .key file you generated when creating the CSR, to the directory on the server where you keep your certificate and key files.

    Note: Make them readable by root only to increase security.

    Find the Apache configuration file (httpd.conf) you need to edit.

    The location and name of the configuration file can vary from server to server—especially if you're using a special interface to manage your server configuration.

    Apache's main configuration file is typically named httpd.conf or apache2.conf. Possible locations for this file include /etc/httpd/ or /etc/apache2/. For a comprehensive listing of default installation layouts for Apache HTTPD on various operating systems and distributions, see Httpd Wiki - DistrosDefaultLayout.

    Often, the SSL certificate configuration is located in a <VirtualHost> block in a different configuration file. The configuration files may be under a directory like /etc/httpd/vhosts.d/, /etc/httpd/sites/, or in a file called httpd-ssl.conf.

    One way to locate the SSL Configuration on Linux distributions is to search using grep, as shown in the example below.

    Run the following command:

    grep -i -r "SSLCertificateFile" /etc/httpd/

    Note: Make sure to replace /etc/httpd/ with the base directory for your Apache installation.

    Identify the SSL <VirtualHost> block you need to configure.

    If your site needs to be accessible through both secure (https) and non-secure (http) connections, you need a virtual host for each type of connection. Make a copy of the existing non-secure virtual host and configure it for SSL as described in step 4.

    If your site only needs to be accessed securely, configure the existing virtual host for SSL as described in step 4.

    Configure the <VirtualHost> block for the SSL-enabled site

    Below is a very simple example of a virtual host configured for SSL. The parts listed in blue are the parts you must add for SSL configuration.

    <VirtualHost 192.168.0.1:443> DocumentRoot /var/www/html2 ServerName www.yourdomain.com SSLEngine on SSLCertificateFile /path/to/your_domain_name.crt SSLCertificateKeyFile /path/to/your_private.key SSLCertificateChainFile /path/to/DigiCertCA.crt </VirtualHost>

    Make sure to adjust the file names to match your certificate files.

    SSLCertificateFile is your DigiCert certificate file (e.g., your_domain_name.crt).

    SSLCertificateKeyFile is the .key file generated when you created the CSR (e.g., your_private.key).

    SSLCertificateChainFile is the DigiCert intermediate certificate file (e.g., DigiCertCA.crt)

    Note: If the SSLCertificateChainFile directive does not work, try using the SSLCACertificateFile directive instead.

    Test your Apache configuration file before restarting.

    As a best practice, check your Apache configuration file for any errors before restarting Apache.

    Caution: Apache won't start again if your configuration files have syntax errors.

    Run the following command to test your configuration file (on some systems, it's apache2ctl):

    apachectl configtest

    Restart Apache.

    You can use apachectl commands to stop and start Apache with SSL support.

    apachectl stop apachectl start

    Restart Notes:

    If Apache doesn't restart with SSL support, try using apachectl startssl instead of apachectl start. If SSL support only loads with apachectl startssl, we recommend you adjust the apache startup configuration to include SSL support in the regular apachectl start command. Otherwise, your server may require to manually restart Apache using apachectl startssl in the event of a server reboot. This usually involves removing the <IfDefine SSL> and </IfDefine> tags that enclose your SSL configuration.

    Congratulations! You've successfully installed your SSL certificate.

    Testing Your SSL/TLS Certificate Installation

    Browser Test

    For best results, make sure to close your web browser first and then re-launch it.

    Visit your site with the secure https URL (i.e., go to https://www.example.com not http://www.example.com).

    Be sure to test your site with more than just Internet Explorer. IE downloads missing intermediate certificates; whereas, other browsers give an error if all the certificates in the certificate chain aren't installed properly.

    0 comments No comments