In this tutorial we are going to configure https protocol for Apache and Nginx both of Web server In Ubuntu Operating System
$ sudo su
$ mkdir -p /etc/apache2/ssl
$ cd /etc/apache2/ssl
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/localhost.key -out /etc/apache2/ssl/localhost.crt
Generating a RSA private key........................................................................+++++............................+++++
writing new private key to '/etc/apache2/ssl/localhost.key'-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:NewYork
Locality Name (eg, city) []:NewYork
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tech2Towards Pvt. Ltd.
Organizational Unit Name (eg, section) []: IT
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:local@localhost.com
Step 2) Make virtual host for https protocol.
$ sudo vim /etc/apache2/sites-available/localhost-ssl.conf
- Add Below Content
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/localhost.crt
SSLCertificateKeyFile /etc/apache2/ssl/localhost.key
</VirtualHost>
</IfModule>
Step 3) Enable some configuration of apache webserver
$ sudo a2enmod ssl
$ sudo a2ensite localhost-ssl.conf
$ sudo service apache2 restart
$ sudo apachectl -t
$ sudo apachectl -S
Step 4) Finally In Browser write https://localhost/
- Click on advance and Click on Proceed to…
For Nginx WebServer
Step 1) Genrate ssl Certificate Files for localhost
$ sudo su
$ mkdir -p /etc/nginx/ssl
$ cd /etc/nginx/ssl
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/localhost.key -out /etc/nginx/ssl/localhost.crt
Generating a RSA private key........................................................................+++++............................+++++writing new private key to '/etc/apache2/ssl/localhost.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:NewYork
Locality Name (eg, city) []:NewYork
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tech2Towards Pvt. Ltd.
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:local@localhost.com
Step 2) Make virtual host for https protocol.
$ nano /etc/nginx/sites-available/localhost-ssl.conf
- Add Below Content
server {
listen 443 ssl;
listen [::]:443 ssl;
root /var/www/html/http;
server_name localhost;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}
Step 3) Enable some configuration of Nginx webserver
$ sudo ln -s /etc/nginx/sites-available/localhost-ssl.conf /etc/nginx/sites-enable/localhost-ssl.conf
$ sudo nginx -t
$ sudo service nginx restart
No comments:
Post a Comment
testing