HTTP/2 in Nginx

SYSTEM INFORMATION
OS type and version: Ubuntu Linux 20.04.2
Webmin version: Webmin version 1.973
Virtualmin version: Virtualmin version 6.16
Related products version: Nginx version 1.18.0/PHP 8.0.9

I need to add HTTP/2 in ngnix config file but I faced with error
Also I tried any code but the resault was the same… and I don’t know what should I to fix that.

You’ve put that directive in the wrong place, as the error indicates.

It should be inside of a virtual host section (in /etc/nginx/sites-available/domain-name.conf on Ubutnu).

1 Like

I still have problem in activate the http2 in nginx

I used this code

server {
    listen 443 ssl http2 default_server;

    ssl_certificate     server.crt;
    ssl_certificate_key server.key;
    …
}

But I changed the ssl_certificate path and name
and added this

server {
    listen 80;
    location / {
        return 301 https://$host$request_uri;
    }
}

But still get http/1 in https://gtmetrix.com/

Also after changes the Web server was stop and start but…

  1. You don’t need to manually add this:

     server {
       listen 80;
       location / {
         return 301 https://$host$request_uri;
       }
     }
    
  2. The ssl certificate path is automatically generated and added by Virtualmin when you request a certificate for a virtual server.

  3. Revert the changes you made to this line listen 443 ssl http2 default_server; back to the default generated by Virtualmin and just add http2 to it.

  4. Restart Nginx.


TLDR: To enable http2, you don’t have to change anything in the default Virtualmin-generated virtual host file except add http2 to this line:

listen xxx.xxx.xxx.xx ssl;

So it’ll look like this:

listen xxx.xxx.xxx.xx ssl http2;

And then simply restart Nginx.

2 Likes

Yes , With your help now its using the HTTP/2 protocol and thank you.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.