Nginx web server with SSL

Some Web sites, such as on-line stores, require secure communication (HTTPS) to protect credit-card transactions and customer information. Like Apache, Nginx supports HTTPS via an SSL module, and it’s very easy to set up.
In this tutorial i use hostname srv-web01.nginx.vn with the ip address 10.11.218.251.
First, you need to generate an SSL certificate. The openssl command will ask you a bunch of questions, but you simply can press Enter for each one:
# yum install openssl
# mkdir /etc/nginx/ssl
# cd /etc/nginx/ssl
# openssl req -new -x509 -nodes -days 265 -newkey rsa:2048 -out server.crt -keyout server.key
Create a new config file called /etc/nginx/sites-available/nginx.vn, which contains the following:

server {

listen 443;

server_name nginx.vn;

root /var/www/nginx.vn

index index.html index.htm

access_log /var/log/nginx/nginx.vn-access.log;

error_log /var/log/nginx/nginx.vn-error.log;

ssl on;

ssl_certificate /etc/nginx/ssl/server.crt;

ssl_certificate_key /etc/nginx/ssl/server.key;

}
Create the root directory and index.html file:
# mkdir /var/www/nginx.vn
# cd /var/www/nginx.vn
# echo “Nginx web server with SSL” > index.html
Enable the site and restart Nginx:
# cd /etc/nginx/sites-enabled
# ln -s ../sites-available/nginx.vn .
# /etc/init.d/nginx restart
open your web browser and go to https://10.11.218.251/

Comments

Popular posts from this blog

Redirect all unencrypted traffic to HTTPS in Apache

Web Servers Load balancing with HAProxy

Using nginx as http load balancer