Flipkart

Monday, July 2, 2018

How To Create an SSL Certificate on Nginx for CentOS

Prerequisites
# yum update
# yum install nginx
Create the SSL Certificate
Create a folder for ssl
sudo mkdir /etc/nginx/ssl


Now that we have a location to place our files, we can create the SSL key and certificate files
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
The entirety of the prompts will look something like this:
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:US
Locality Name (eg, city) []:US City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:TECH
Organizational Unit Name (eg, section) []:IN
Common Name (e.g. server FQDN or YOUR name) []:tech.com
Email Address []:admin@ tech.com
Configure Nginx to Use SSL
Your server block may look something like this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name your_domain.com;
location / {
try_files $uri $uri/ =404;
}
}
Should be look like this.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
root /usr/share/nginx/html;
index index.html index.htm;
server_name your_domain.com;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
When you are finished, save and close the file.
Now, all you have to do is restart Nginx to use your new settings:
sudo service nginx restart
location / {
try_files $uri $uri/ =404;
}
}

Test your Setup
clip_image001
https://server_domain_or_IP
clip_image002

















































No comments:

Post a Comment