Install Nginx anyway (AWS Amazon Linux 2, CentOS7 compatible, official ref. Available)

environment

--Assuming you want to install Nginx on your AWS EC2 instance --OS: Amazon Linux2 or CentOS7 (RHEL7 series) ** \ * I learned later ** --Nginx: 1.18.0 (latest, stable, as of 2020.8.31)

Install Nginx

For Amazon Linux 2

Install from the amazon-linux-extras repository

List of installable packages

$ amazon-linux-extras

...

 38  nginx1=latest            enabled      [ =stable ] #here
 39  ruby2.6                  available    [ =2.6  =stable ]
 40  mock                     available    [ =stable ]
 41  postgresql11             available    [ =11  =stable ]
 42  php7.4                   available    [ =stable ]
 43  livepatch                available    [ =stable ]
 44  python3.8                available    [ =stable ]
 45  haproxy2                 available    [ =stable ]

Install

$ sudo amazon-linux-extras install nginx1

↓ To common work ↓

reference

Install software from Extras Library on Amazon Linux 2 EC2 instance


##For CentOS
Add the official repository and install from there

##Added official repository

$ vi /etc/yum.repos.d/nginx.repo


Added below

[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/releasever/basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true

[nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/releasever/basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true


### Install

sudo yum install nginx


###reference
[nginx: Linux packages](http://nginx.org/en/linux_packages.html)

#Common work below

## Run & Auto-Run enable & Show status
Start Nginx, enable automatic start, display status
(CentOS assumes 7 or later, the command seems to be different if it is 6 or earlier)

sudo systemctl start nginx && sudo systemctl enable nginx && systemctl status nginx


## Backup nginx.config
Back up the config file
**Very important, especially if you are new to Nginx**

`/etc/nginx/nginx.conf`Backup

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.back


**`/etc/nginx/conf.d/default.conf`If there is(New version 1.18.Confirm with 0)**
`/etc/nginx/conf.d/default.conf`Backup
**As far as I can confirm, Nginx version1.12.0 is default.The content of conf is nginx.Although it was described in conf, 1.18.0 is conf.d/default.Exists as an independent directive as conf**

sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.back


#Frequently used Nginx commands

##Start / Status display / Exit
The command is Amazon Linux 2,Can be used in common with CentOS7
The base of Amazon Linux 2 is RHEL7, which seems to be the same as CentOS7
[What kind of distribution does amazon linux support?-Stack overflow](https://ja.stackoverflow.com/questions/50113/amazon-linux-%E3%81%AF%E4%BD%95%E7%B3%BB%E3%81%AE%E3%83%87%E3%82%A3%E3%82%B9%E3%83%88%E3%83%AA%E3%83%93%E3%83%A5%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AB%E5%AF%BE%E5%BF%9C%E3%81%99%E3%82%8B)

$ systemctl start nginx

$ systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server ...

$ systemctl stop nginx


##Reload settings(Frequently used)

$ sudo systemctl reload nginx


##Enable auto-start

sudo systemctl enable nginx



 



Recommended Posts

Install Nginx anyway (AWS Amazon Linux 2, CentOS7 compatible, official ref. Available)
[AWS EC2] How to install Maven on Amazon Linux 2
Install tomcat 5.5 on Amazon Linux.
Make Amazon Linux 2 (CentOS) GUI
Install Homebrew on Amazon Linux 2
Install strongSwan 5.9.1 on Amazon Linux 2
Install Python Pillow on Amazon Linux
Install oracle java8 on amazon linux2
How to install wkhtmltopdf (Amazon Linux2)
Install pyenv on EC2 (Amazon Linux)
[Note] Install Imagick on Amazon Linux2