How To Install nginx on CentOS 6 Using yum

Saturday, February 4, 2017

How To Install nginx on CentOS 6 with yum


there are below step to install nginx on centOS 6 using Yum Command.

Install From Repository

if you want to install nginx from repository than start from step 1 otherwise start from step 5.

Step 1. cd /etc/yum.repos.d

Step 2. Create a repo configuration file for Nginx
           vi nginx.repo

Step 3. Put the following lines to nginx.conf
           [nginx]
           name=nginx repo
           baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
           gpgcheck=0
           enabled=1

Step 4. Save changes and exit the text editor.

Step 5. install EPEL
             EPEL is fo Extra Packages for Enterprise Linux. yum as a package manager does not include the latest version of nginx in its default repository, son need to install EPEL, will make sure that nginx on CentOS stays up to date.
          command prompt> sudo yum install epel-release

Step 6. Install nginx
           command prompt> sudo yum install nginx

Step 7. Start nginx
           command prompt> sudo /etc/init.d/nginx start


Configure Nginx

Step 1. Open the Nginx configuration file
           vi /etc/nginx/nginx.conf

Step 2. Modify the worker_process value to reflect the number of processor cores installed in the server.
           worker_processes 2

Step 3. To enable gzip compression, find the following line:
           #gzip on
          And uncomment it
          gzip on

Step 4. Save changes and exit the text editor.
    
Step 5. Restart the Nginx daemon to apply your changes.
            service nginx restart

Step 6. Configure Nginx to automatically start after reboot.
            chkconfig nginx on


Configure The Default Website

Step 1. Open the default website configuration file.
            vi /etc/nginx/conf.d/default.conf

Step 2. To set the listening port, find the following line and modify it’s value:
            listen 80;

Step 3. Set the DNS hostname of your website by finding the following line and replacing localhost with the name of your server.
           server_name localhost;

Step 4. The default website root directory is /usr/share/nginx/html. To change it, find the following lines and replace the highlighted value with the desired file path.

          location / { 
                  root /usr/share/nginx/html; 
                  index index.html index.htm; 
          }

5. To modify the default index file, add to or replace the values listed next to index.

6. Save changes and exit the text editor.


Configure Firewall To Allow HTTP Access

Step 1. Run the following command to allow HTTP access through IPTables.
            iptables -A INPUT -m state --state NEW -P tcp --dport 80 -j ACCEPT

Step 2. To permanently save the firewall rule, run the following command.
            /sbin/service iptables save





























0 comments:

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP