LinuxMoz

Linux Stuff && Coffee

How to Install Nginx on CentOS / RHEL

| Comments

Normally I install Nginx on CentOS / RHEL via the EPEL repo, however I have recently discovered the Nginx project has it’s own repo available. Note this will install a much newer Nginx version than the one available in the EPEL repo, follow the steps below to install Nginx on CentOS / RHEL.

Create the file /etc/yum.repo.d/nginx.repo and populate it with the following text (depending on your distro / version number).

Nginx CentOS 6 YUM Repo

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

Nginx CentOS 5 YUM Repo

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/5/$basearch/
gpgcheck=0
enabled=1

Nginx RHEL 6 YUM Repo

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/rhel/6/$basearch/
gpgcheck=0
enabled=1

Nginx RHEL 5 YUM Repo

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/rhel/5/$basearch/
gpgcheck=0
enabled=1

Yum Install Nginx (CentOS / RHEL)

Next you can simply yum install the latest version of nginx using:

1
yum install nginx

NOTE if you are only running one website and your html files are at the default site location updating Nginx via yum will overwrite your website files with the default Nginx site files. I recommend you install your website at a different location to avoid this, you should also check out my tutorial on optimizing Nginx for high traffic websites (currently writing will link here once it’s complete).

Comments