How to install Nginx on CentOS
Nginx is a free, open-source, high-performance HTTP known for its stability, rich feature set, simple configuration, and low resource consumption.
To install Nginx using yum we will need to include the EPEL (Extra Packages for Enterprise Linux) repository.
One thing to keep in mind when adding extra repositories is that many include newer versions of packages that are readily available through the standard channels. This can cause problems as packages can be automatically upgraded and cease to function as expected.
EPEL repository is purely complimentary and only provides additional packages otherwise unavailable through the default repositories.
Installing the EPEL repository
The command will depend on your CentOS version and the machine type (32 or 64 bit):
cat /etc/redhat-release; uname -m
Now, depending on the output, install the EPEL repository:
CentOS 5.x i386:sudo rpm -ivh http://mirror.yandex.ru/epel/5/i386/epel-release-5-4.noarch.rpmCentOS 5.x x86_64:
sudo rpm -ivh http://mirror.yandex.ru/epel/5/x86_64/epel-release-5-4.noarch.rpmCentOS 6.x i386:
sudo rpm -ivh http://mirror.yandex.ru/epel/6/i386/epel-release-6-8.noarch.rpmCentOS 6.x x86_64:
sudo rpm -ivh http://mirror.yandex.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm
Installing Nginx using Yum
Installing nginx using Yum is now very simple, thanks to EPEL, run:
sudo yum install nginx
As this will be the first package we install using EPEL, we will be asked to import the EPEL gpg-key.
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Importing GPG key 0x0608B895: Userid : EPEL (6) Package: epel-release-6-5.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Is this ok [y/N]: y
This key is used to sign all packages that are associated with the EPEL repository to verify their validity.
Once the gpg-key has been imported, the installation should proceed as expected.
Starting Nginx
Nginx is not started automatically, to start Nginx run:
# sudo /etc/init.d/nginx start
To check if it works navigate to your IP address:
http://111.222.333.444
To start Nginx on boot run:
sudo /sbin/chkconfig nginx on
Controlling Nginx is done with these commands:
sudo /etc/init.d/nginx start ... sudo /etc/init.d/nginx stop ... sudo /etc/init.d/nginx reload ... sudo /etc/init.d/nginx restart
You can also check the current status as well as the configuration syntax by using the following commands:
sudo /etc/init.d/nginx status ... sudo /etc/init.d/nginx configtest
The configtest option is particularly useful for testing your Nginx configuration before actually applying it with a reload or restart.
- How to install Nginx, PHP 5.3.10 and PHP-FPM on CentOS 5.7 — 6.2
- How to fix OpenSSL Heartbleed vulnerability on CentOS
- How to fix accept() failed (24: Too many open files) error in Nginx
- How to install Nginx in FreeBSD
- NAXSI: protecting websites with Nginx
- How to fix 413 error: Request Entity Too Large in Nginx
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
Cintia
2013-01-11 12:15:29
|
Hi, worked as planned, thanks, however when I now run the Plesk updater I get this message. Would you be able to advise: WARNING: Third-party Yum repository epel' is enabled, installation may fail. Since you use one or more 3rd-party repos (say, atomic), be careful when installing different package versions from different repos as this may lead to installation failures. For example, you may encounter a problem if you first install PHP from a 3rd-party repo and then upgrade it using the Parallels repo. To avoid such situations, install and upgrade packages from the same repo. Thanks! David |
Got a comment?