KenoKivabe

Your Essential Queries

Author
Md Mojahedul Islam
06 Aug, 2022

How To Create Self Signed SSL Certificate


We'll See How To Create and Use Self Signed SSL Certificate for Nginx Server:

1) Open Terminal

2) Make a directory to store SSL certificates:

  1. sudo makdir /etc/nginx/ssl;   

3) Generate SSL certificate using openSSL

  1. sudo openssl req -x509 -days 60 -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/self.key -out /etc/nginx/ssl/self.cert

4) Use SSL certificate with Nginx Server


  1. server {  
  2.     listen 80;  
  3.     server_name _;  
  4.     return 301 https://$host$request_uri;  
  5. }  
  6.   
  7. server {  
  8.     listen 443;  
  9.   
  10.     root "/var/www/hosting/public_html/public";  
  11.     index index.php index.html index.htm index.nginx-debian.html;  
  12.   
  13.     server_name _;  
  14.   
  15.     ssl_certificate /etc/nginx/ssl/self.cert;  
  16.     ssl_certificate_key /etc/nginx/ssl/self.key;  
  17.   
  18.     location / {  
  19.         try_files $uri $uri/ =404;  
  20.     }  
  21.   
  22.     location ~ \.php$ {  
  23.         include snippets/fastcgi-php.conf;  
  24.         fastcgi_pass unix:/run/php/php7.4-fpm.sock;  
  25.     }  
  26.   
  27.     location ~ /\.ht {  
  28.         deny all;  
  29.     }  
  30. }  

Share: