Yum install Nginx latest build (1.13.9+ / 1.15+) in Amazon EC2 (AMI Linux) and enable HTTP2/Server Push – 安装 Nginx 最新版本到 EC2 上,并启用 HTTP2/Server Push

Preface

From Nginx v1.13.9, we gain HTTP2/Server Push eventually.

Here is the doc for you to install it, via yum for Amazon EC2 (Amazon AMI Linux)

Steps

Add repo

sudo vim /etc/yum.repos.d/nginx.repo

Add followed:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/rhel/6/$basearch/
gpgcheck=0
enabled=1

Allow extra duplicated packages besides Amazon AMI Linux repo

sudo vim /etc/yum/pluginconf.d/priorities.conf 
[main]
enabled = 0

Yum Update

# update
sudo yum update

Show duplicated repo candidates and install it

repoquery --show-duplicates nginx

Terminal Output:

nginx-0:1.11.11-1.el6.ngx.x86_64
nginx-0:1.11.12-1.el6.ngx.x86_64
nginx-0:1.11.13-1.el6.ngx.x86_64
nginx-0:1.13.0-1.el6.ngx.x86_64
nginx-0:1.13.1-1.el6.ngx.x86_64
nginx-0:1.13.2-1.el6.ngx.x86_64
nginx-0:1.13.3-1.el6.ngx.x86_64
nginx-0:1.13.4-1.el6.ngx.x86_64
nginx-0:1.13.5-1.el6.ngx.x86_64
nginx-0:1.13.6-1.el6.ngx.x86_64
nginx-0:1.13.7-1.el6.ngx.x86_64
nginx-0:1.13.8-1.el6.ngx.x86_64
nginx-0:1.13.9-1.el6.ngx.x86_64
nginx-0:1.13.10-1.el6.ngx.x86_64
nginx-0:1.13.11-1.el6.ngx.x86_64
nginx-0:1.13.12-1.el6.ngx.x86_64
nginx-0:1.15.0-1.el6.ngx.x86_64
nginx-0:1.15.1-1.el6.ngx.x86_64
nginx-0:1.15.2-1.el6.ngx.x86_64
nginx-0:1.15.3-1.el6.ngx.x86_64
nginx-1:1.12.1-1.33.amzn1.x86_64

Select latest and install it

# assume nginx-0:1.15.3-1.el6.ngx.x86_64 is the latest
sudo yum remove nginx
sudo yum install --setopt=obsoletes=0  -y nginx-0:1.15.3-1.el6.ngx.x86_64

Change Nginx config

suod vim /etc/nginx/conf.d/YOUR_CONFIG_FILE

File content

server {

        # listen 443 ssl;
        listen 443 ssl http2;

        # SSL configuration
        #
        listen [::]:443 ssl http2;
        # ...
        }

        root /PATH_TO_YOUR_DOC_ROOT;
        http2_push_preload on;



 location ~ .php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # Or fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;
                #fastcgi_index   index.php;

                # nginx 1.13.9+
                #include fastcgi.conf;
                include fastcgi_params;

                fastcgi_param   SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
                fastcgi_intercept_errors on;
                #fastcgi_pass php;
        }

Restart Nginx and check

sudo service nginx restart
nginx -v

Terminal output

nginx version: nginx/1.15.3

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.