• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Ubuntu 16.04 Apache2 HTTP/2, HSTS : Steps + Configuration

By Abhishek Ghosh May 31, 2017 10:02 am Updated on May 23, 2018

Ubuntu 16.04 Apache2 HTTP/2, HSTS : Steps + Configuration

Advertisement

As we said before – we are no longer supporting to install, configure Nginx but we are back to support Apache2 mainly for their odd idea to involve community to develop modules for free and distribute with paid product. Additionally, Nginx 502 error is a nightmare. Apache2 at current cost of web hosting not exactly bad. Here is a full working guided steps to setup Ubuntu 16.04 Apache2 HTTP/2, HSTS easily.

Ubuntu 16.04 Apache2 HTTP:2, HSTS - Steps + Configuration

 

Ubuntu 16.04 Apache2 HTTP/2, HSTS : Steps

 

We will use ondrej’s repository for Apache2, first update and add the repo :

Vim
1
2
sudo apt-get update
sudo add-apt-repository ppa:ondrej/apache2

After adding the repo, again update and install Apache2 :

Advertisement

---

Vim
1
sudo apt-get install apache2

To activate the http2 module, simply run :

Vim
1
a2enmod http2

Next restart Apache2 :

Vim
1
2
systemctl restart apache2
# sudo systemctl restart apache2.service

For practical reasons, we need SSL/HTTPS, so we will take it granted that you did these steps :

Vim
1
2
3
4
5
6
a2enmod ssl
systemctl restart apache2
# sudo systemctl restart apache2.service
a2ensite default-ssl
systemctl restart apache2
# sudo systemctl restart apache2.service

And for free SSL/TLS certificate, you have done something like these :

Vim
1
2
apt-get -y install python-letsencrypt-apache
apt-get -y install python-certbot-apache

To generate SSL certificates against your domains you did these :

Vim
1
letsencrypt --apache -d abhishekghosh.pro -d www.abhishekghosh.pro

Then had a restart :

Vim
1
2
systemctl restart apache2
# sudo systemctl restart apache2.service

You essentially can open your website’s HTTPS version on browser without warning. If your virtual host configuration file’s name is 000-default-le-ssl.conf with this (partial) content :

Vim
1
2
3
4
5
6
7
8
9
10
11
<IfModule mod_ssl.c>
<VirtualHost *:443>
       ServerName abhishekghosh.pro
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/html
 
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/abhishekghosh.pro/fullchain.pem
...
...

You should add this line :

Vim
1
Protocols http/1.1 h2

here :

Vim
1
2
3
4
5
6
7
8
9
10
11
<IfModule mod_ssl.c>
<VirtualHost *:443>
Protocols http/1.1 h2
       ServerName abhishekghosh.pro
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/html
 
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/abhishekghosh.pro/fullchain.pem
...

Ans restart Apache2 after config test :

Vim
1
2
apachectl -t
sudo systemctl restart apache2.service

Now, if you test somewhere for HTTP/2, you’ll get it. For adding different headers, you need to activate a module :

Vim
1
a2enmod headers

and restart Apache2 :

Vim
1
2
systemctl restart apache2
# sudo systemctl restart apache2.service

We already talked about HSTS in context of Nginx.

The configuration for HSTS should look like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<IfModule mod_ssl.c>
<VirtualHost *:443>
Protocols http/1.1 h2
       ServerName abhishekghosh.pro
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/html
 
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/abhishekghosh.pro/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/abhishekghosh.pro/privkey.pem
 
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomainsi; preload"
...

and restart Apache2 :

Vim
1
2
systemctl restart apache2
# sudo systemctl restart apache2.service

 

Example Virtual Hosts Configuration File For Ubuntu 16.04 Apache2 HTTP/2, HSTS

 

It is an example modern, secured setup :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<IfModule mod_ssl.c>
<VirtualHost *:443>
Protocols http/1.1 h2
       ServerName abhishekghosh.pro
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/html
 
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/abhishekghosh.pro/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/abhishekghosh.pro/privkey.pem
### For paid SSL follow their guide for cert installation
# SSLCertificateFile /etc/ssl/private/public.crt
# SSLCertificateKeyFile /etc/ssl/private/private.key
# SSLCertificateChainFile /etc/ssl/private/intermediate.crt
### End third party SSL cert block
 
SSLOpenSSLConfCmd DHParameters "/etc/ssl/private/dhparams_4096.pem"
SSLOpenSSLConfCmd ECDHParameters secp384r1
SSLOpenSSLConfCmd Curves secp521r1:secp384r1
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomainsi; preload"
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options SAMEORIGIN
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
Include /etc/letsencrypt/options-ssl-apache.conf
 
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <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
 
</VirtualHost>
 
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
</IfModule>

We kept other settings on /etc/letsencrypt/options-ssl-apache.conf file. Which essentially has :

Vim
1
2
3
4
5
6
7
8
9
10
11
SSLEngine on
 
SSLProtocol             all -SSLv2 -SSLv3
SSLCipherSuite          (find latest cipher suitable for you and add here)
SSLHonorCipherOrder     on
SSLCompression          off
 
SSLOptions +StrictRequire
 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common

In case we want to enable HTTP Public Key Pinning (HPKP), Expect-CT etc headers, we will add headers in this fashion :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
...
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomainsi; preload"
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options SAMEORIGIN
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
Header always set Public-Key-Pins 'pin-sha256="add-your-pin"; pin-sha256="add-your-another-pin"; max-age=5184000; includeSubDomains'
Header set X-XSS-Protection "1; mode=block"
Header set Expect-CT "enforce; max-age=3600"
Header set Referrer-Policy "origin"
FileETag None
Include /etc/letsencrypt/options-ssl-apache.conf
 
    <Directory />

Quite simple. Test on SSL Lab and Security Headers like easy to test sites :

Vim
1
2
https://www.ssllabs.com/ssltest/analyze.html
https://securityheaders.io

Of course you can use HTTP/2 server push feature with Apache2. Please read the official docs on Apache’s site for more information.

Tagged With ubuntu apache2 xss block , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1838 OoPuoYiXGDb5ib0nYNPbeZS6pNnq6djlBSJNE-SNbINnvHC2SXESHhxS9_yHmn3J 9753a63031ae2c64fa0e00dde9e18cc20e3d6607&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1824 xfocc2KLPQWl5uSXcgG9-2lkxuW8IHeSyab3d3_epJSUcuXj7eHXxPNjYNY_J6g2 19b258141e62443e33298fdbe777e685c0b132c9&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme , Expect-CT letsencrypt , enforce https on apache2 ubuntu 16 04 , apache2 after http2 header edit set-cookie no longer working , Apache2 , apache ubuntu require hsts , apache hsts ubuntu , apache HSTS
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Ubuntu 16.04 Apache2 HTTP/2, HSTS : Steps + Configuration

  • How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS

    Here is Detailed Guide on How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS With Commands and Configurations For Most Secured Setup.

  • Easy Steps To Setup Let’s Encrypt on Ubuntu 16.04, Nginx

    Here Are Easy Steps To Setup Let’s Encrypt on Ubuntu 16.04, Nginx With HSTS, ALPN on HTTP/2, OCSP Stapling, Public Key Pinning (HPKP), Cipher.

  • Free SSL : How to Install Let’s Encrypt on Ubuntu, Nginx

    Here is Step by Step Commands to Use Free SSL by Let’s Encrypt. We will use aptitude software to install the certificate, it is very easy.

  • Join/Merge Multiple Log Files For Big Data Analysis

    Here Are The Ways To Join/Merge Multiple Log Files For Big Data Analysis, Store Them To OpenStack Based Cloud Storage And Delete Old Files.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy