CentOS 7 is a great Linux distribution but one thing it does lack is an official Nginx package in the default distribution mirrors. There are a few methods of working around this including the use of EPEL but for this tutorial I will use Nginx’s official repository for the installation.
Let’s get started!
Establishing a connection to the repository via yum is simple. simply create and edit a new repository file as shown below:
add the following:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Next we will install the nginx server by running the following yum installation command:
yum install nginx
You will have to acknowledge the install but you can make this silent by adding a -y to the installation command if you wish.
One the installation is completed you can start the nginx server by running the following command:
service nginx start
You will probably want nginx to auto start at boot time. In CentOS 7 you will use the following systemd command to do this:
systemctl enable nginx
You can verify it is properly enabled by running the following command in systemd:
systemctl is-enabled nginx
If the output says “enabled” then nginx is properly set to start on boot.
Here’s a few examples of useful commands to help you in the event you are having issues with your nginx server.
Check the sanity of a config file:
[example@proxy ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Check the status of the nginx server:
[example@proxy ~]# service nginx status Redirecting to /bin/systemctl status nginx.service nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled) Active: active (running) since Sun 2015-02-15 11:15:22 CST; 25min ago Docs: http://nginx.org/en/docs/ Main PID: 28703 (nginx) CGroup: /system.slice/nginx.service ├─28703 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─28704 nginx: worker process Feb 15 11:15:22 proxy.01.example.com nginx: nginx: the configuration... Feb 15 11:15:22 proxy.01.example.com nginx: nginx: configuration fil... Feb 15 11:15:22 proxy.01.example.com systemd: Started nginx - high perfo... Hint: Some lines were ellipsized, use -l to show in full.
In the event these two check out and it’s still not working you probably have a connectivity issue. The default policies on CentOS 7 have http blocked so that would be a great place to start assuming connectivity has been verified.
On a parting note one last step I would recommend when tidying up the install would be to disable the version header. You can edit the nginx.conf and add the following directive to do this:
This guide was meant to be very basic and I plan on doing a deeper dive into virtual hosts, proxies, and addition configurations in a future post.
Hope you enjoy!