|
| 1 | +--- |
| 2 | +title: 'How to install an SSL certificate on a VPS' |
| 3 | +excerpt: 'Find out how to install an SSL certificate on an OVHcloud VPS' |
| 4 | +updated: 2025-01-24 |
| 5 | +--- |
| 6 | + |
| 7 | +## Objective |
| 8 | + |
| 9 | +Securing your website is essential to protect your users' sensitive data and improve their trust. With an SSL certificate (**S**ecure **S**ockets **L**ayer), you can encrypt the exchanges between your visitors and your website, while strengthening its credibility. This guide documents the use of **Let's Encrypt**, a free and automated service. |
| 10 | + |
| 11 | +**Find out how to install an SSL certificate on an OVHcloud VPS.** |
| 12 | + |
| 13 | +> [!warning] |
| 14 | +> |
| 15 | +> OVHcloud provides services that you are responsible for with regard to their configuration and management. It is therefore your responsibility to ensure that they function properly. |
| 16 | +> |
| 17 | +> We offer this tutorial to help you with common tasks. Nevertheless, we recommend contacting a [specialist provider](/links/partner) and/or the service's publisher if you encounter any difficulties. We will not be able to assist you. More information in the [Go further](#gofurther) section of this tutorial. |
| 18 | +> |
| 19 | +
|
| 20 | +## Requirements |
| 21 | + |
| 22 | +- A [Virtual Private Server](/links/bare-metal/vps) in your OVHcloud account |
| 23 | +- Administrative access (sudo) via SSH to your server |
| 24 | +- A functional website accessible in `HTTP` |
| 25 | + |
| 26 | +## Instructions |
| 27 | + |
| 28 | +### Summary |
| 29 | + |
| 30 | +- [Step 1 - Log in to your OVHcloud VPS](#step1) |
| 31 | +- [Step 2 - Install Certbot](#step2) |
| 32 | +- [Step 3 - Get an SSL certificate with Let's Encrypt](#step3) |
| 33 | +- [Step 4 - Configure your web server](#step4) |
| 34 | +- [Step 5 - Enable automatic renewal](#step5) |
| 35 | + |
| 36 | +### Step 1 - Log in to your OVHcloud VPS <a name="step1"></a> |
| 37 | + |
| 38 | +1. Download an SSH client like [PuTTY](/pages/web_cloud/web_hosting/ssh_using_putty_on_windows) or use your operating system's built-in terminal. |
| 39 | +2. Log in to your OVHcloud VPS with the login information provided: |
| 40 | + |
| 41 | +```bash |
| 42 | +ssh root@<vps_ip> |
| 43 | +``` |
| 44 | + |
| 45 | +Replace `<vps_ip>` with the IP address of your OVHcloud VPS. |
| 46 | + |
| 47 | +### Step 2 - Install Certbot <a name="step2"></a> |
| 48 | + |
| 49 | +Certbot is a tool to automatically manage Let's Encrypt certificates. Follow the steps below to install Certbot according to your Linux distribution. |
| 50 | + |
| 51 | +> [!tabs] |
| 52 | +> **Ubuntu/Debian** |
| 53 | +>> |
| 54 | +>> ```bash |
| 55 | +>> sudo apt update |
| 56 | +>> sudo apt install certbot |
| 57 | +>> ``` |
| 58 | +>> |
| 59 | +> **CentOS** |
| 60 | +>> |
| 61 | +>> ```bash |
| 62 | +>> sudo yum install epel-release |
| 63 | +>> sudo yum install certbot |
| 64 | +>> ``` |
| 65 | +>> |
| 66 | +> **Fedora** |
| 67 | +>> |
| 68 | +>> ```bash |
| 69 | +>> sudo dnf install certbot |
| 70 | +>> ``` |
| 71 | +
|
| 72 | +Verify that Certbot is properly installed by running the following command: |
| 73 | +
|
| 74 | +```bash |
| 75 | +certbot --version |
| 76 | +``` |
| 77 | +
|
| 78 | +This should show the version of Certbot installed. |
| 79 | + |
| 80 | +### Step 3 - Get an SSL certificate with Let's Encrypt <a name="step3"></a> |
| 81 | + |
| 82 | +> [!primary] |
| 83 | +> |
| 84 | +> If you have set up your web server (Nginx or Apache), we recommend using Certbot plugins to automate SSL configuration and enable `HTTPS` redirections. These plugins simplify the installation by directly managing the configuration files of the web server. |
| 85 | +
|
| 86 | +#### Automatic use with Certbot Nginx or Apache plugins (recommended) |
| 87 | + |
| 88 | +Depending on your web server, use the corresponding command lines: |
| 89 | + |
| 90 | +> [!tabs] |
| 91 | +> **Nginx** |
| 92 | +>> |
| 93 | +>> Install the Certbot Nginx plugin: |
| 94 | +>> |
| 95 | +>> ```bash |
| 96 | +>> sudo apt install python3-certbot-nginx -y |
| 97 | +>> ``` |
| 98 | +>> |
| 99 | +>> Generate the SSL certificate: |
| 100 | +>> |
| 101 | +>> ```bash |
| 102 | +>> sudo certbot --nginx -d your_domain |
| 103 | +>> ``` |
| 104 | +>> |
| 105 | +> **Apache** |
| 106 | +>> |
| 107 | +>> Install the Apache Certbot plugin: |
| 108 | +>> |
| 109 | +>> ```bash |
| 110 | +>> sudo apt install python3-certbot-apache -y |
| 111 | +>> ``` |
| 112 | +>> |
| 113 | +>> Generate the SSL certificate: |
| 114 | +>> |
| 115 | +>> ```bash |
| 116 | +>> sudo certbot --apache -d your_domain |
| 117 | +>> ``` |
| 118 | +
|
| 119 | +Certbot will automatically configure the SSL certificate and `HTTPS` redirection. Check that your website is accessible in `HTTPS`. |
| 120 | +
|
| 121 | +#### Standalone usage |
| 122 | +
|
| 123 | +If you prefer to configure your server manually, use Certbot in standalone mode. This mode uses a temporary server built into Certbot to validate your domain name and generate an SSL certificate. |
| 124 | +
|
| 125 | +Use the following command to request a certificate: |
| 126 | +
|
| 127 | +```bash |
| 128 | +sudo certbot certonly --standalone -d your_domain |
| 129 | +``` |
| 130 | +
|
| 131 | +Replace `your_domain` with your domain name. |
| 132 | + |
| 133 | +> [!warning] |
| 134 | +> This method temporarily stops any service using port 80 (for example, another web server). |
| 135 | +
|
| 136 | +Once the certificate has been generated, the files are available in `/etc/letsencrypt/live/your_domain/`: |
| 137 | + |
| 138 | +- `fullchain.pem`: the full certificate. |
| 139 | +- `privkey.pem`: the private key. |
| 140 | + |
| 141 | +### Step 4 - Configure your web server <a name="step4"></a> |
| 142 | + |
| 143 | +> [!primary] |
| 144 | +> If you have used the automatic solution (with Certbot plugins) before ([Step 3](#step3)) and your website is accessible in `HTTPS`, go directly to the [Step 5](#step5) of this guide. |
| 145 | +
|
| 146 | +#### Example for Nginx |
| 147 | + |
| 148 | +1\. Open your website's configuration file (for example, `/etc/nginx/sites-available/your_domain.conf`). |
| 149 | + |
| 150 | +2\. Add the following lines to activate SSL: |
| 151 | + |
| 152 | +```nginx |
| 153 | +server { |
| 154 | + listen 443 ssl; |
| 155 | + server_name your_domain; |
| 156 | +
|
| 157 | + ssl_certificate /etc/letsencrypt/live/your_domain/fullchain.pem; |
| 158 | + ssl_certificate_key /etc/letsencrypt/live/your_domain/privkey.pem; |
| 159 | +
|
| 160 | + # Paramètres de sécurité supplémentaires |
| 161 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 162 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 163 | +
|
| 164 | + # Redirection HTTP vers HTTPS |
| 165 | + location / { |
| 166 | + try_files $uri $uri/ =404; |
| 167 | + } |
| 168 | +} |
| 169 | +``` |
| 170 | + |
| 171 | +3\. Add an automatic `HTTP` to `HTTPS` redirection: |
| 172 | + |
| 173 | +```nginx |
| 174 | +server { |
| 175 | + listen 80; |
| 176 | + server_name your_domain; |
| 177 | + return 301 https://$host$request_uri; |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +4\. Test and restart Nginx: |
| 182 | + |
| 183 | +```bash |
| 184 | +sudo nginx -t |
| 185 | +sudo systemctl reload nginx |
| 186 | +``` |
| 187 | + |
| 188 | +Check that your website is accessible in `HTTPS`. |
| 189 | + |
| 190 | +#### Example for Apache |
| 191 | + |
| 192 | +1\. Enable SSL modules and headers: |
| 193 | + |
| 194 | +```bash |
| 195 | +sudo a2enmod ssl |
| 196 | +sudo a2enmod headers |
| 197 | +``` |
| 198 | + |
| 199 | +2\. Modify your website's configuration (e.g. `/etc/apache2/sites-available/your_domain.conf`) to include: |
| 200 | + |
| 201 | +```apache |
| 202 | +<VirtualHost *:80> |
| 203 | + ServerName your_domain |
| 204 | + DocumentRoot /var/www/your_domain |
| 205 | +
|
| 206 | + Redirect permanent / https://your_domain/ |
| 207 | +
|
| 208 | + <Directory /var/www/your_domain> |
| 209 | + AllowOverride All |
| 210 | + Require all granted |
| 211 | + </Directory> |
| 212 | +
|
| 213 | + ErrorLog ${APACHE_LOG_DIR}/ssltest_error.log |
| 214 | + CustomLog ${APACHE_LOG_DIR}/ssltest_access.log combined |
| 215 | +</VirtualHost> |
| 216 | +
|
| 217 | +<VirtualHost *:443> |
| 218 | + ServerName your_domain |
| 219 | + DocumentRoot /var/www/your_domain |
| 220 | +
|
| 221 | + # Activer SSL |
| 222 | + SSLEngine on |
| 223 | + SSLCertificateFile /etc/letsencrypt/live/your_domain/fullchain.pem |
| 224 | + SSLCertificateKeyFile /etc/letsencrypt/live/your_domain/privkey.pem |
| 225 | +
|
| 226 | + # Paramètres de sécurité supplémentaires |
| 227 | + SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 |
| 228 | + SSLCipherSuite HIGH:!aNULL:!MD5 |
| 229 | + SSLHonorCipherOrder on |
| 230 | +
|
| 231 | + <Directory /var/www/your_domain> |
| 232 | + AllowOverride All |
| 233 | + Require all granted |
| 234 | + </Directory> |
| 235 | +
|
| 236 | + ErrorLog ${APACHE_LOG_DIR}/ssltest_error.log |
| 237 | + CustomLog ${APACHE_LOG_DIR}/ssltest_access.log combined |
| 238 | +</VirtualHost> |
| 239 | +``` |
| 240 | + |
| 241 | +4\. Test and restart Apache: |
| 242 | + |
| 243 | +```bash |
| 244 | +sudo apachectl configtest |
| 245 | +sudo systemctl restart apache2 |
| 246 | +``` |
| 247 | + |
| 248 | +Check that your website is accessible in `HTTPS`. |
| 249 | + |
| 250 | +### Step 5 - Enable automatic renewal <a name="step5"></a> |
| 251 | + |
| 252 | +Let's Encrypt certificates are valid for 90 days. Configure automatic renewal with Certbot: |
| 253 | + |
| 254 | +Test automatic renewal: |
| 255 | + |
| 256 | +```bash |
| 257 | +sudo certbot renew --dry-run |
| 258 | +``` |
| 259 | + |
| 260 | +Certbot automatically configures a `cron` task or a systemd timer to manage renewal. Check its status with: |
| 261 | + |
| 262 | +```bash |
| 263 | +sudo systemctl list-timers | grep certbot |
| 264 | +``` |
| 265 | + |
| 266 | +## Go further <a name="go-further"></a> |
| 267 | + |
| 268 | +For specialized services (SEO, development, etc.), contact the [OVHcloud partners](/links/partner). |
| 269 | + |
| 270 | +Join our [community of users](/links/community). |
0 commit comments