Skip to content
Rashid Azar

SSL setup on Nginx Server

Linux, Web server1 min read

To add https support on your website you need to follow these steps:

Get the SSL certificate

There are various vendors from which you can buy SSL certificate. If you want to generate self signed SSL certificate instead of buying it, please execute below command:

1$ sudo openssl req -x509 -newkey rsa:4096 -keyout ssl.key -out ssl.cert -days 365

Add -nodes in the above command if you do not want to set any passphrase for your private key.

Copy certificate to right location

Once the certificate is generated copy it to /etc/ssl/ folder on your server.

Update virtual host file

Open your virtual host config file ( /etc/nginx/sites-enabled/your_site.conf):

1server {
2 listen 80 ;
3 server_name pma.rashidazar.com;
4 return 301 https://your_site.com$request_uri;
5}
6
7server {
8 listen 443 ssl;
9 ssl on;
10 server_name your_site.com;
11 root /var/www/html/your_site;
12 client_max_body_size 5m;
13 add_header X-UA-Compatible "IE=Edge,chrome=1";
14
15 access_log /var/log/nginx/your_site.com.access.log;
16 error_log /var/log/nginx/your_site.com.error.log;
17
18 ssl_certificate /etc/ssl/ssl.cert;
19 ssl_certificate_key /etc/ssl/ssl.key;
20
21 index index.php index.html index.htm;
22
23 location / {
24 try_files $uri $uri/ /index.php$is_args$args;
25 }
26
27 location ~ \.php$ {
28 try_files $fastcgi_script_name =404;
29 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
30 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
31 include fastcgi_params;
32 }
33}
© 2021 by Rashid Azar. All rights reserved.