How to Install Nginx on CentOS 7
Nginx [engine x] is free and open source high-performance web server. It also acts as a reverse proxy server, as well as. This page shows how to install Nginx server on a CentOS 7 or RHEL 7 and configure a static web site.
In this article, we will explain how to install, configure and manage Nginx HTTP web server on a CentOS 7 or RHEL 7 server using command line.
Install Nginx Web Server
- First update the system software packages to the latest version.
- Next, install Nginx HTTP server from the EPEL repository using the YUM package manager, or if you have not installed the epel repository you can install the nginx repository.
# yum -y update |
Configure EPEL repo
# yum install epel-release |
Configure Nginx repo for CentOS 7 & RHEL (Red Hat Enterprise Linux) version 7.x
# vi /etc/yum.repos.d/nginx.repo |
Append following for CentOS 7.x:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1 |
Append following for RHEL (Red Hat Enterprise Linux) version 7.x:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/rhel/7/$basearch/ gpgcheck=0 enabled=1 |
Next, install Nginx
# yum install nginx |
Manage Nginx HTTP Server
- Once Nginx web server installed, you can start it first time and enable it to start automatically at system boot.
# systemctl
start nginx # systemctl enable nginx # systemctl status nginx |
Configure firewalld to Allow Nginx Traffic
- By default, CentOS 7 and RHEL 7 built-in firewall is set to block Nginx traffic. To allow web traffic on Nginx, update the system firewall rules to permit inbound packets on HTTP and HTTPS using the commands below.
#
firewall-cmd --zone=public --permanent --add-service=http # firewall-cmd --zone=public --permanent --add-service=https # firewall-cmd --reload |
Test Nginx Server on CentOS 7 and RHEL 7
- Now you can verify Nginx server by going to the following URL, a default nginx page will be shown.
http://SERVER_DOMAIN_NAME_OR_IP |
You can also use the curl command to get same info using the cli:
$ curl -I
http://10.21.136.13 $ curl http://10.21.136.13 |
Nginx Important Files and Directories
- The default server root directory (top level directory containing configuration files): /etc/nginx.
- The main Nginx configuration file: /etc/nginx/nginx.conf.
- Server block (virtual hosts) configurations can be added in: /etc/nginx/conf.d.
- The default server document root directory (contains web files): /usr/share/nginx/html.
Tidak ada komentar:
Posting Komentar