Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to install SSL certificate in Nginx

To install an SSL certificate in Nginx, we will need the following files:

  • Certificate (.crt)
  • Private key (.key)
  • Certification Authority (.ca)

You already have them? Let’s start:

  1. Copy the three files on the server. In this manual we assume that you have uploaded all three files via FTP, but you can do it in any other way.

  2. Connect to the server via SSH and access the directory where the certificates are located. If you have uploaded them to the 'web' directory: cd /var/www/minuevaweb.es/datos/web

  3. Concatenate the .crt file with the .ca file, and save it in the Nginx certificate directory: cat /var/www/minuevaweb.es/datos/web/certificado.crt /var/www/minuevaweb.es/datos/web/certificado.ca >> /etc/nginx/swhosting/ssl/certificados.crt

  4. Move the .key file to the Nginx certificate directory: mv /var/www/minuevaweb.es/datos/web/certificado.key /etc/nginx/ssl/

  5. We remove the certificate files from the web folder to make sure they are not public. rm /var/www/minuevaweb.es/datos/web/certificado.crt rm /var/www/minuevaweb.es/datos/web/certificado.ca

  6. Access the certificate directory and change the owner and group thereof to root: cd /etc/nginx/ssl chown root:root certificados.crt certificado.key

We have already copied the certificates in the corresponding directory.

Next, we proceed to modify the configuration file corresponding to our website:

  • Access the configuration files directory vhosts: cd /etc/nginx/sites-enabled/

  • Edit the configuration file corresponding to the web in which you are installing the SSL certificate. In this example, we use the text editor nano, but you can use any other: nano minuevaweb.es.conf

  • We make a copy of the first block under it, being duplicated:

# nginx virtual host for domain 'minuevaweb.es'
server {
        listen 80;
        root "/var/www/minuevaweb.es/datos/web";
        index index.html index.php;
        server_name minuevaweb.es www.minuevaweb.es;
        access_log /var/www/minuevaweb.es/logs/20190307.log;
        error_log /var/www/minuevaweb.es/logs/error_20190307.log;
        include /etc/nginx/php7.2.conf;
}

(the original file)

server {
        listen 80;
        root "/var/www/minuevaweb.es/datos/web";
        index index.html index.php;
        server_name minuevaweb.es www.minuevaweb.es;
        access_log /var/www/minuevaweb.es/logs/20190307.log;
        error_log /var/www/minuevaweb.es/logs/error_20190307.log;
        include /etc/nginx/php7.2.conf;
}
server {
        listen 80;
        root "/var/www/minuevaweb.es/datos/web";
        index index.html index.php;
        server_name minuevaweb.es www.minuevaweb.es;
        access_log /var/www/minuevaweb.es/logs/20190307.log;
        error_log /var/www/minuevaweb.es/logs/error_20190307.log;
        include /etc/nginx/php7.2.conf;
}

(the file with the original copy)

  • In the second block, we modify the port from 80 to 443:
server {
        listen 443;
        ...
  • In the second block, after the port (parameter listen), we add the following lines with the corresponding routes to our certificates:
        ...
        ssl on;
        ssl_certificate /etc/nginx/ssl/certificados.crt;
        ssl_certificate_key /etc/nginx/ssl/certificado.key;
        ...
  • It will be as follows:
# nginx virtual host for domain 'minuevaweb.es'
server {
        listen 80;
        root "/var/www/minuevaweb.es/datos/web";
        index index.html index.php;
        server_name minuevaweb.es www.minuevaweb.es;
        access_log /var/www/minuevaweb.es/logs/20190307.log;
        error_log /var/www/minuevaweb.es/logs/error_20190307.log;
        include /etc/nginx/php7.2.conf;
}
server {
        listen 443;
        ssl on;
        ssl_certificate /etc/nginx/ssl/certificados.crt;
        ssl_certificate_key /etc/nginx/ssl/certificado.key;
        root "/var/www/minuevaweb.es/datos/web";
        index index.html index.php;
        server_name minuevaweb.es www.minuevaweb.es;
        access_log /var/www/minuevaweb.es/logs/20190307.log;
        error_log /var/www/minuevaweb.es/logs/error_20190307.log;
        include /etc/nginx/php7.2.conf;
}
  • We keep the changes made. In the text editor nano, you have to press the following key combination: Ctrl + X to save and exit Y key to confirm that you want to overwrite Enter key

  • We check that the configuration is correct: nginx -t If an error appears, review the previous steps.

  • We reload the Nginx configuration so that the changes are applied: /etc/init.d/nginx reload

Ready! Access your website with the prefix https:// to verify that it works correctly.

If you prefer, we can perform this management for you. Request it through a ticket for technical action.

More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
More than 2000 m² of own facilities and Data Centers in Spain
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.