root@nplink:/etc/nginx/sites-available# nginx -V
nginx version: nginx/1.1.19
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx.
.
.
To generate an RSA key, use the genrsa option. The command below generates a 2048 bit RSA key and saves it to a file called key.pem
(No password protected)
# Local modifications will be overwritten.
#
#getting ridn of www
server {
listen 192.168.140.30:80 default;
server_name hello.com *.hello.com;
##redirect http to https ##
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
ssl_certificate /etc/nginx/ssl/helloSSL/selfsignedSSLCRT.crt;
ssl_certificate_key /etc/nginx/ssl/helloSSL/nprivate.key;
access_log /var/log/nginx/default-access.log;
error_log /var/log/nginx/default-error.log;
root /var/www/hello.com/public_html;
index index.html index.htm;
##start ssl config
listen 192.168.140.30:443 ssl;
server_name hello.com *.hello.com;
########## redirect to https##########
if ($host = 'www.hello.com' ) {
rewrite ^/(.*)$ https://hello.com/$1 permanent;
}
}
=========================================================
# ln -s /etc/nginx/sites-available/hello.com /etc/nginx/sites-enabled/hello.com
# ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
---------------------------------------------------------------------------------
place your file in /var/www/
##service nginx reload or restart and check
nginx version: nginx/1.1.19
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx.
.
.
To generate an RSA key, use the genrsa option. The command below generates a 2048 bit RSA key and saves it to a file called key.pem
(No password protected)
openssl genrsa -out privatekey.pem 2048
If you require that your private key file is protected with a passphrase, use the command below.
openssl genrsa -des3 -out privatekey.pem 2048
here private key i generated is named 'privatekey.pem'
Now removing password..
# openssl rsa -in privatekey.pem -out nprivate.key
Creating CSR certificate sigining request:
# openssl req -new -key nprivate.key -out CSRself.csr
----------------------------------------------------------
Signing and creating certificate with csr
# openssl x509 -req -days 365 -in CSRself.csr -signkey nprivate.key -out selfsignedSSLCRT.crt
root@nplink:/etc/nginx/ssl/helloSSL# pwd
/etc/nginx/ssl/helloSSL
root@nplink:/etc/nginx/ssl/helloSSL# ls
CSRself.csr nprivate.key selfsignedSSLCRT.crt
There are two virtual hosts 1)example.com 2)hello.com
hello.com implementing ssl
root@nplink:/etc/nginx/sites-available# ls
example.com hello.com
root@nplink:/etc/nginx/sites-available# cat hello.com
# Generated by Chef for nplink (nginx version: 1.1.19)# Local modifications will be overwritten.
#
#getting ridn of www
server {
listen 192.168.140.30:80 default;
server_name hello.com *.hello.com;
##redirect http to https ##
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
ssl_certificate /etc/nginx/ssl/helloSSL/selfsignedSSLCRT.crt;
ssl_certificate_key /etc/nginx/ssl/helloSSL/nprivate.key;
access_log /var/log/nginx/default-access.log;
error_log /var/log/nginx/default-error.log;
root /var/www/hello.com/public_html;
index index.html index.htm;
##start ssl config
listen 192.168.140.30:443 ssl;
server_name hello.com *.hello.com;
########## redirect to https##########
if ($host = 'www.hello.com' ) {
rewrite ^/(.*)$ https://hello.com/$1 permanent;
}
}
=========================================================
root@nplink:/etc/nginx/sites-available# cat example.com
# Generated by Chef for nplink (nginx version: 1.1.19)
#
# Local modifications will be overwritten.
#
server {
listen 192.168.140.30:80;
server_name example.com *.example.com;
access_log /var/log/nginx/default-access.log;
error_log /var/log/nginx/default-error.log;
root /var/www/example.com/public_html;
index index.html index.htm;
}
------------------------------------------------------------
create soft link of example.com and hello.com in sites-enabled with full path
# ln -s /etc/nginx/sites-available/hello.com /etc/nginx/sites-enabled/hello.com
# ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
---------------------------------------------------------------------------------
place your file in /var/www/
##service nginx reload or restart and check
No comments:
Post a Comment