How to install nginx using yum

How to install nginx using yum

There are 2 ways to install nginx, you can install by source or by using yum command. In this article , Please introduce to you guys how to install

How to create a SSL Certificate on Nginx for Centos
How to Install zPanel on Ubuntu 12.04
How To Install And Manage Java On Ubuntu

There are 2 ways to install nginx, you can install by source or by using yum command.

In this article , Please introduce to you guys how to install nginx using yum command.

Step 1: Install Repo

# cd  /tmp
# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

Show output like below:

# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
warning: nginx-release-centos-6-0.el6.ngx.noarch.rpm: Header V4 RSA/SHA1 Signatu re, key ID 7bd9bf62: NOKEY
Preparing… ########################################### [100%]
1:nginx-release-centos ########################################### [100%]

 

Step 2: Install Nginx Web Server

Run follow command to install nginx

# yum install nginx

Sample output:

# yum install nginx
Loaded plugins: fastestmirror, refresh-packagekit
Setting up Install Process
Determining fastest mirrors
epel/metalink | 5.0 kB 00:00
* base: virror.hanoilug.org
* epel: mirrors.vinahost.vn
* extras: virror.hanoilug.org
* updates: mirror.vietoss.com
base | 3.7 kB 00:00
epel | 4.4 kB 00:00
epel/primary_db | 6.4 MB 00:03
extras | 3.4 kB 00:00
google-chrome | 951 B 00:00
google-chrome/primary | 1.9 kB 00:00
http://dl.google.com/linux/chrome/rpm/stable/x86_64/repodata/primary.xml.gz: [Errno -1] Metadata file does not match checksum
Trying other mirror.
nginx | 2.9 kB 00:00
nginx/primary_db | 34 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 2.6 MB 00:01
Resolving Dependencies
–> Running transaction check
—> Package nginx.x86_64 0:1.6.2-1.el6.ngx will be installed
–> Finished Dependency ResolutionDependencies Resolved=================================================================
Package Arch Version Repository Size
========================================================================
Installing:
nginx x86_64 1.6.2-1.el6.ngx nginx 336 kTransaction Summary
========================================================================
Install 1 Package(s)Total download size: 336 k
Installed size: 828 k
Is this ok [y/N]: y
Downloading Packages:
nginx-1.6.2-1.el6.ngx.x86_64.rpm | 336 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : nginx-1.6.2-1.el6.ngx.x86_64 1/1
———————————————————————-Thanks for using nginx!Please find the official documentation for nginx here:
* http://nginx.org/en/docs/Commercial subscriptions for nginx are available on:
* http://nginx.com/products/———————————————————————-
Verifying : nginx-1.6.2-1.el6.ngx.x86_64 1/1Installed:
nginx.x86_64 0:1.6.2-1.el6.ngxComplete!

 

Step 3: Add Nginx into startup program

Typing follow command to execute:

# chkconfig nginx on
# chkconfig –level 235 nginx o

How do I start | stop | restart | reload nginx

# service nginx start
# service nginx stop
# service nginx restart
# service nginx status
# service nginx reload

 

Step 4: Nginx Configuration

  1. Default configuration directory: /etc/nginx/
  2. Default SSL and vhost config directory: /etc/nginx/conf.d/
  3. Default log file directory: /var/log/nginx/
  4. Default document root directory: /usr/share/nginx/html
  5. Default configuration file: /etc/nginx/nginx.conf
  6. Default server access log file: /var/log/nginx/access.log
  7. Default server access log file: /var/log/nginx/error.log

Step 5: Optimize Nginx Configuration

– Worker Processes and Worker Connections

Check the number of processor that Server is having

# grep processor /proc/cpuinfo | wc -l

check our core’s limitations by issuing a ulimit command

# ulimit -n

Edit  worker_processes is equal with number processor of Server and worker_connections is equal with our core’s limitations

Step 6: Start Nginx 

# /etc/init.d/nginx start

Step 7: Check Nginx Status

# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:5910 0.0.0.0:* LISTEN 1946/Xvnc
tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 1924/xrdp-sesman
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1441/sshd
tcp 0 0 127.0.0.1:5911 0.0.0.0:* LISTEN 4251/Xvnc
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1330/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1523/master
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 1919/xrdp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19378/nginx
tcp 0 0 :::22 :::* LISTEN 1441/sshd
tcp 0 0 ::1:631 :::* LISTEN 1330/cupsd
tcp 0 0 ::1:25 :::* LISTEN 1523/master
udp 0 0 0.0.0.0:5353 0.0.0.0:* 5438/chrome
udp 0 0 0.0.0.0:631 0.0.0.0:* 1330/cupsd

 Step 8: Open firewall for Nginx

Edit iptable

# vim /etc/sysconfig/iptables

Add this command in the iptables file

-A INPUT -m state –state NEW -p tcp –dport 80 -j ACCEPT

Restart iptable to active editing

# service iptables restart

 

Step 9: Check Website status

Go to the link http://ip_address to test status of website

Good luck to you guys


COMMENTS

WORDPRESS: 0
DISQUS: 0