This blog is related to setup SSL cert over Nginx server if you have .cert & .key file then you are able to setup this SSL If you don't have any please create locally or purchase from SSL provides.
SSL give use a secure socket protection which help to keep our domain / website heathy.
Below is the simple steps .
1) Upload your .cert & .key file on your server like Amazon Ec2 / Digital Ocean using any tool or "scp" ubuntu command.
2) Install Nginx on your server.
3) After successfully installation you need to create a ssl_certs Folder in /etc/nginx/
mkdir /etc/nginx/ssl_certs please check once if the folder is already exist then don't need to create the folder again .
SSL give use a secure socket protection which help to keep our domain / website heathy.
Below is the simple steps .
1) Upload your .cert & .key file on your server like Amazon Ec2 / Digital Ocean using any tool or "scp" ubuntu command.
2) Install Nginx on your server.
- sudo apt-get update
- sudo apt-get install nginx
3) After successfully installation you need to create a ssl_certs Folder in /etc/nginx/
mkdir /etc/nginx/ssl_certs please check once if the folder is already exist then don't need to create the folder again .
4) Put your .cert & .key file in /etc/nginx/ssl_certs folder
5) Edit: /etc/nginx/sites-available/default and add your domain as per my given configuration.
6) Restart you nginx server
5) Edit: /etc/nginx/sites-available/default and add your domain as per my given configuration.
6) Restart you nginx server
- sudo systemctl restart nginx # New version of Ubuntu 16.04
- sudo service nginx restart # older version of Ubuntu 14.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Location of this file : /etc/nginx/sites-available/default | |
# This configuration for NodeJs application but the configuration is same for other framework also like ruby-on-rails. | |
# Make sure if you have AWS EC2 instance then please open the HTTPS port to serve the application on Https protocols. | |
# Also if you need extra port on same domain enable thoes port over AWS EC2 instance. | |
# In this configuration I am using same domain but with different port. | |
server { | |
listen 80; | |
server_name your.domain.com; | |
# return 301 https://$server_name$request_uri; | |
location / { | |
proxy_pass http://127.0.0.1:8081/; | |
} | |
} | |
server { | |
listen 443; | |
ssl on; | |
ssl_certificate /etc/nginx/ssl_certs/xxx_xxx_example.crt; | |
ssl_certificate_key /etc/nginx/ssl_certs/xxx_example.key; | |
server_name your.domain.com; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
location / { | |
proxy_pass http://127.0.0.1:8081; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
} | |
# This is for the other node Js backend server to deal with mongodb API | |
server { | |
listen 8082; | |
ssl on; | |
ssl_certificate /etc/nginx/ssl_certs/xxxx_example.crt; | |
ssl_certificate_key /etc/nginx/ssl_certs/xxxx_example.key; | |
server_name your.domain.com; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
location / { | |
proxy_pass http://localhost:7001; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
} |