DEV Community

Dries Deboosere
Dries Deboosere

Posted on • Originally published at driesdeboosere.dev on

How to enable HTTP/2 on NGINX

In this post, I'll explain how you can setup your NGINX for HTTP/2.

Go to your nginx.conf or default configuration file. In my case I'll need to change my NGINX default configuration file;

nano /etc/nginx/sites-available/default
Enter fullscreen mode Exit fullscreen mode

This should look something like this;

server {
    listen 80;
    server_name driesdeboosere.dev *.driesdeboosere.dev;
    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/driesdeboosere.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/driesdeboosere.dev/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
Enter fullscreen mode Exit fullscreen mode

Add http2 after ssl:

listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
listen 443 ssl http2; # managed by Certbot
Enter fullscreen mode Exit fullscreen mode

Now save your changes to the NGINX config file and reload NGINX:

systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Well done! Now your NGINX server uses HTTP/2!

Top comments (0)