{"id":5971,"date":"2015-02-20T16:12:12","date_gmt":"2015-02-20T08:12:12","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5971"},"modified":"2023-04-28T09:47:18","modified_gmt":"2023-04-28T09:47:18","slug":"how-to-install-nginx-on-centos-7-rhel-7","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-nginx-on-centos-7-rhel-7\/","title":{"rendered":"How to Install Nginx on CentOS 7 \/ RHEL 7"},"content":{"rendered":"<p>NGINX is a web server that focuses to high performance and high concurrency and at the same time very low memory usage. It is a flexible web server and lightly if compare to the Apache HTTP Web Server. Since the advent of RHEL 7 and CentOS 7, many webmasters or system administrators and the owner of Virtual Private Server (VPS) or dedicated server start to find a best way to update and install Nginx on CentOS 7 and RHEL 7. The article below discusses how to install Nginx with two method option and the steps are tested on CentOS 7 and RHEL 7 operating system.<\/p>\n<h3>OPTION A. Install Nginx &#8211; Source Installation :<\/h3>\n<p>1. Install Nginx software prerequisites :<\/p>\n<pre># yum install pcre pcre-devel openssl-devel perl gcc make -y\n<\/pre>\n<p>2. Create Nginx user :<\/p>\n<pre># useradd nginx\n# usermod -s \/sbin\/nologin nginx\n<\/pre>\n<p>3. Create the following directory to keep all the installation files and logs :<\/p>\n<pre># mkdir -p \/etc\/nginx\n# mkdir -p \/var\/log\/nginx\n# mkdir -p \/var\/cache\/nginx\n<\/pre>\n<p>4. Download Nginx from official website and extract it :<\/p>\n<pre># wget http:\/\/nginx.org\/download\/nginx-1.6.2.tar.gz\n# tar xzvf nginx-1.6.2.tar.gz\n<\/pre>\n<p>5. Go to the extracted directory and start Compiling and install Nginx :<\/p>\n<pre># cd nginx-1.6.2\n<\/pre>\n<pre># <em>.\/configure --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'<\/em>\n<\/pre>\n<p>If your Nginx software compiling is successful, you will received below configuration summary :<\/p>\n<pre>Configuration summary\n  + using system PCRE library\n  + using system OpenSSL library\n  + md5: using OpenSSL library\n  + sha1: using OpenSSL library\n  + using system zlib library\n\n  nginx path prefix: \"\/etc\/nginx\"\n  nginx binary file: \"\/usr\/sbin\/nginx\"\n  nginx configuration prefix: \"\/etc\/nginx\"\n  nginx configuration file: \"\/etc\/nginx\/nginx.conf\"\n  nginx pid file: \"\/var\/run\/nginx.pid\"\n  nginx error log file: \"\/var\/log\/nginx\/error.log\"\n  nginx http access log file: \"\/var\/log\/nginx\/access.log\"\n  nginx http client request body temporary files: \"\/var\/cache\/nginx\/client_temp\"\n  nginx http proxy temporary files: \"\/var\/cache\/nginx\/proxy_temp\"\n  nginx http fastcgi temporary files: \"\/var\/cache\/nginx\/fastcgi_temp\"\n  nginx http uwsgi temporary files: \"\/var\/cache\/nginx\/uwsgi_temp\"\n  nginx http scgi temporary files: \"\/var\/cache\/nginx\/scgi_temp\"\n<\/pre>\n<p>6. Still in the current, nginx-1.x.x directory, issue the installation command as below :<\/p>\n<pre># make &amp;&amp; make install\n<\/pre>\n<p>7. Register Nginx service into systemd as a service by create the file named nginx.service :<\/p>\n<pre># vi \/usr\/lib\/systemd\/system\/nginx.service\n<\/pre>\n<p>Add the following :<\/p>\n<pre><em>[Unit]\nDescription=nginx - high performance web server\nDocumentation=http:\/\/nginx.org\/en\/docs\/\nAfter=network.target remote-fs.target nss-lookup.target\n\n[Service]\nType=forking\nPIDFile=\/run\/nginx.pid\nExecStartPre=\/usr\/sbin\/nginx -t -c \/etc\/nginx\/nginx.conf\nExecStart=\/usr\/sbin\/nginx -c \/etc\/nginx\/nginx.conf\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/bin\/kill -s QUIT $MAINPID\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target<\/em>\n<\/pre>\n<p>8. Start Nginx service and make it start at boot :<\/p>\n<pre># sudo systemctl start nginx.service\n# sudo systemctl enable nginx.service\n<\/pre>\n<p>9. Stop and disable Firewalld service :<\/p>\n<pre># sudo systemctl stop firewalld.service\n# sudo systemctl disable firewalld.service\n<\/pre>\n<h3>OPTION B. Install Nginx &#8211; Installation via yum repository :<\/h3>\n<p>1. To enable automatic updates of Linux packages set up the yum repository for the RHEL\/CentOS distributions, you can added manually without installing the nginx-release package. Create the file named \/etc\/yum.repos.d\/nginx.repo with the following contents:<\/p>\n<pre># vi \/etc\/yum.repos.d\/nginx.repo\n<\/pre>\n<pre><em>[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/OS\/OSRELEASE\/$basearch\/\ngpgcheck=0\nenabled=1<\/em>\n<\/pre>\n<p>Note : Please replace &#8220;OS&#8221; with &#8220;<strong>rhel<\/strong>&#8221; or &#8220;<strong>centos<\/strong>&#8220;, depending on the distribution used, and &#8220;<strong>OSRELEASE<\/strong>&#8221; with CentOS or RHEL version such as &#8220;5&#8221;, &#8220;6&#8221;, or &#8220;7&#8221;, for 5.x, 6.x, or 7.x versions, respectively.<\/p>\n<p>As an example for RHEL 7 :<\/p>\n<pre><em>[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/rhel\/7\/$basearch\/\ngpgcheck=0\nenabled=1<\/em>\n<\/pre>\n<p>2. Alternatively you can install the prepare yum repository using nginx-release package followed by the OS version.<\/p>\n<p>a) RHEL 7 :<\/p>\n<pre># rpm -Uvh http:\/\/nginx.org\/packages\/rhel\/7\/noarch\/RPMS\/nginx-release-rhel-7-0.el7.ngx.noarch.rpm\n<\/pre>\n<p>b) CentOS 7 :<\/p>\n<pre># rpm -Uvh http:\/\/nginx.org\/packages\/centos\/7\/noarch\/RPMS\/nginx-release-centos-7-0.el7.ngx.noarch.rpm\n<\/pre>\n<p>3. Start install Nginx with yum command :<\/p>\n<pre># yum install nginx -y\n<\/pre>\n<p>How to verify the both installation method are successful or not ?<\/p>\n<p>Visit http:\/\/Nginx-ipaddres<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-5982 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/centos7-nginx.png\" alt=\"install nginx\" width=\"600\" height=\"354\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/centos7-nginx.png 600w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/02\/centos7-nginx-300x177.png 300w\" data-sizes=\"(max-width: 600px) 100vw, 600px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 600px; --smush-placeholder-aspect-ratio: 600\/354;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NGINX is a web server that focuses to high performance and high concurrency and at the same time very low memory usage. It is a flexible web server and lightly&#8230;<\/p>\n","protected":false},"author":6,"featured_media":5533,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,1014,2058],"tags":[1605],"class_list":["post-5971","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-nginx","category-rhel","tag-nginx"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5971"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5971\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/5533"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}