Changes between Version 2 and Version 3 of secureweb


Ignore:
Timestamp:
Nov 23, 2016, 5:28:33 PM (8 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • secureweb

    v2 v3  
    9797== Enabling Virtual Hosts ==
    9898
    99 Before we go further test your domain names are correctly resolving to the same server IP address by issuing Ubuntu dig commands.
    100 {{{
    101 dig @192.248.1.161 web1.’yourdomain’.ws.learn.ac.lk
    102 dig @192.248.1.161 web2.’yourdomain’.ws.learn.ac.lk
    103 }}}
    104 Next, create two directories on /var/www/ to host two separate web sites.
     99Create two directories on /var/www/ to host two separate web sites.
    105100{{{
    106101sudo mkdir /var/www/web1
     
    156151sudo a2ensite web2.conf
    157152}}}
    158 Now restart the apache and check your browsers for following and see how three websites are hosted in one server.
     153Now restart the apache.
     154
     155Do a nslookup for www.yourdomain.ws.learn.ac.lkand find the IP Addressof yourweb server and edit your pc host file and include following.(assume your IP is 192.248.X.X)
     156{{{
     157192.248.X.Xweb1.yourdomain.ws.learn.ac.lk
     158192.248.X.Xweb2.yourdomain.ws.learn.ac.lk
     159}}}
     160'''Note''':
     161For Linux:host file is /etc/host , edit with  nano as sudo.[[br]]
     162For Windows:host file is %SystemRoot%\System32\drivers\etc\hosts, open with Notepad in Run As Admin mode.
     163
     164and restart your pc’s....
     165
     166check your browsers for following and see how three websites are hosted in one server.
    159167
    160168http://www.yourdomain.ws.learn.ac.lk [[br]]
     
    214222ServerSignature Off
    215223ServerTokens Prod
     224TraceEnable Off
    216225}}}
    217226
     
    286295}}}
    287296Now restart apache and browse to the newly created directory from your browser and check what is changed.
     297
     298== Enabling HTTPS with self-signed certificates ==
     299Create self-signedCertificates on to a directory '''/etc/sslusing opensslsudo openssl'''
     300{{{
     301req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache_prv.key -out /etc/ssl/certs/apache_crt.crt
     302}}}
     303You will be asked series of questions, answer them carefully
     304{{{
     305Country Name (2 letter code) [AU]:LK
     306State or Province Name (full name) [Some-State]:Kandy
     307Locality Name (eg, city) []:Peradeniya
     308Organization Name (eg, company) [Internet Widgits Pty Ltd]:YourInst
     309Organizational Unit Name (eg, section) []:IT Team
     310Common Name (e.g. server FQDN orYOUR name) []:www.yourdomain.ws.learn.ac.lk
     311Email Address []:info@yourdomain.ws.learn.ac.lk
     312}}}
     313Once finished, it will create two files in /etc/ssl. Next create another apacheconfig fileas web1-ssl.conf and include
     314{{{
     315<IfModule mod_ssl.c>
     316    <VirtualHost _default_:443>S
     317         erverAdmin admin@yourdomain.ws.learn.ac.lk
     318         ServerName web1.yourdomain.ws.learn.ac.lk
     319         DocumentRoot /var/www/web1
     320         <Directory /var/www/web1>
     321                  Require all granted
     322         </Directory>
     323         ErrorLog ${APACHE_LOG_DIR}/error.log
     324         CustomLog ${APACHE_LOG_DIR}/access.log
     325         combinedSSLEngine on
     326         SSLCertificateFile      /etc/ssl/certs/apache_crt.crt
     327         SSLCertificateKeyFile /etc/ssl/private/apache_prv.key
     328         <FilesMatch "\.(cgi|shtml|phtml|php)$">
     329                  SSLOptions +StdEnvVars
     330         </FilesMatch>
     331         <Directory /usr/lib/cgi-bin>
     332                  SSLOptions +StdEnvVars
     333         </Directory>
     334         </VirtualHost>
     335</IfModule>
     336}}}
     337Now enable this site by
     338{{{
     339sudo a2enmod ssl
     340sudo a2ensiteweb1-ssl.conf
     341}}}
     342Try browsing https://web1.yourdomain.ws.learn.ac.lk, you will be warned about the untrusted connection as it is a self-signed authentication.
     343
     344== Something Useful ==
     345
     346Also as a best practice it is better to disable port 80 or plain HTTP traffic to your server. But if your directly disable Port 80 and allow only 443 then we have to manually type “https://” before your exact url in browsers. Therefore, better to redirect all HTTP traffic to port443 from your server configuration without disabling. So to do that we need to put a redirect in each virtual host conf. files.
     347
     348Edit port 80 virtual host configuration files and add these in bottom just before the line </VirtualHost>
     349{{{
     350RewriteEngine on
     351RewriteCond %{SERVER_NAME} = www.yourdomain.ws.learn.ac.lk
     352RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
     353</VirtualHost>
     354}}}
     355Then enable mod-rewrite in apache and restart..
     356{{{
     357sudo a2enmod rewrite
     358sudo systemctl reload apache2
     359}}}
     360Now test your configuration by browsing to http://www.yourdomain.ws.learn.ac.lk and see how it redirects
     361== http2 ==
     362HTTP/2 support is included in Apache 2.4.17 and upwards. Enable HTTP/2 module by executing,
     363{{{
     364sudo a2enmod http2
     365}}}
     366then add below to each individual ssl virtual host files to enable respectively.
     367{{{
     368Protocols h2 http/1.1
     369}}}
     370To enable http/2 globally you can add following to the apache.conf
     371{{{
     372Protocols h2 h2c http/1.1
     373}}}
     374Once those lines are added restart apache and visit https://tools.keycdn.com/http2-test to check http2 configuration.
     375
     376== Enable ufw(Ubuntu Firewall) ==
     377Before enabling ufw we must allow all outdoing and deny all incoming traffic as default. Also allowing ssh will be a must.
     378{{{
     379sudo ufw default allow outgoing
     380sudo ufw default deny incoming
     381sudo ufw allow ssh
     382}}}
     383Then enable ufw,
     384{{{
     385sudo ufw enable
     386}}}
     387Press y when asked:
     388{{{
     389Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
     390Firewall is active and enabled on system startup
     391}}}
     392and try to access your server from browser.
     393
     394To enable port 80 and 443 we need,
     395{{{
     396sudo ufw allow 80/tcp
     397sudo ufw allow 443/tcp
     398}}}
     399Check UFW status by
     400{{{
     401sudo ufw status
     402sudo ufw status verbose
     403
     404=== Troubleshoot ===
     405{{{
     406systemctl status apache2.service
     407journalctl –xe
     408}}}
     409Log files:
     410{{{
     411tail –f /var/log/syslog
     412tail –f /var/log/apache2/access.log
     413tail –f /var/log/apache2/error.log
     414}}}
     415
    288416== HTTPS configuration using Let’s Encrypt ==
     417Following are some additional stuff for you to try at your own institute with your own webserver and public IP addresses.
     418
     419Prerequisites:To deploy Let’sEncrypt ssl certificates you must have public DNS and reachability from Internet
     420
    289421Install letsencrypt client on the server
    290422{{{
     
    319451}}}
    320452Above command will execute “/usr/bin/letsencrypt renew” on 25 th day in every two months and will write the output to a file called “/var/log/le-renew.log”
    321 Also as a best practice it is better to disable port 80 or plain HTTP traffic to your server. But if your directly disable Port 80 and allow only 443 then we have to manually type “https://” before your exact url in browsers. Therefore, better to redirect all HTTP traffic to port443 from your server configuration without disabling. So to do that we need to put a redirect in each virtual host conf. files.
    322 
    323 Edit port 80 virtual host configuration files and add these in bottom just before the line </VirtualHost>
    324 {{{
    325 RewriteEngine on
    326 RewriteCond %{SERVER_NAME} = www.yourdomain.ws.learn.ac.lk
    327 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
    328 </VirtualHost>
    329 }}}
    330 Then enable mod-rewrite in apache and restart..
    331 {{{
    332 sudo a2enmod rewrite
    333 sudo systemctl reload apache2
    334 }}}
    335 Now test your configuration by browsing to http://www.yourdomain.ws.learn.ac.lk and see how it redirects
    336 == http2 ==
    337 HTTP/2 support is included in Apache 2.4.17 and upwards. Enable HTTP/2 module by executing,
    338 {{{
    339 sudo a2enmod http2
    340 }}}
    341 then add below to each individual ssl virtual host files to enable respectively.
    342 {{{
    343 Protocols h2 http/1.1
    344 }}}
    345 To enable http/2 globally you can add following to the apache.conf
    346 {{{
    347 Protocols h2 h2c http/1.1
    348 }}}
    349 Once those lines are added restart apache and visit https://tools.keycdn.com/http2-test to check http2 configuration.
     453