How to install nginx on CentOS 7

Nginx is primarily a web server for various protocols such as HTTP, HTTPS, IMAP, POP3 and SMTP. It also performs other functions, including HTTP caching, load balancing and acting as a reverse proxy. Nginx is open-source software that runs on Linux-like operating systems such as CentOS. It’s distributed as a binary package that contains all of the files needed to install nginx, including a public PGP key and configuration file. This installation requires you to install the nginx software repository and then install the actual software from the repository.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
TIME REQUIRED 10 min
RELATED PRODUCTS CentOS-based VPS or dedicated servers

Here is a quick tutorial on how to install nginx on CentOS 7.

Install the nginx software repository

Connect to your server via SSH (more info).

Switch to the root user (more info).

Enter the directory where you’ll install the repository. Assuming you wish to use the tmp directory, you’ll use the following command:

# cd /tmp

Download the appropriate nginx binary package for CentOS. The following wget command downloads the most current version of this package:

# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Install the nginx yum configuration file for this package with the following rpm command:

# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

Install nginx

The following yum command will install nginx from the yum configuration file by automatically answering "yes" to all questions.

# yum install nginx

The yum command will produce output similar to the following if nginx installs successfully:

Enter the following commands to enable and start nginx:

# chkconfig nginx on
# service nginx start

(If you have another service listening on port 80, such as Apache - you will have to stop that service prior to starting nginx. You can also change the port that nginx listens on by modifying the /etc/nginx/conf.d/default.conf file).

Enter the following URL into your browser:

http://127.0.0.1:80

This page should look like the following screenshot if nginx is running correctly:


Was This Article Helpful?
Thanks for your feedback. To speak with a customer service representative, please use the support phone number or chat option above.
Glad we helped! Anything more we can do for you?
Sorry about that. Tell us what was confusing or why the solution didn’t solve your problem.