HAProxy and Nginx in CentOS

Go straight !

login as: root
root@192.168.2.152's password:
Last login: Fri Apr 15 15:08:00 2011

Checking connection

[root@lb01 ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=53 time=28.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=53 time=28.3 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1008ms
rtt min/avg/max/mdev = 28.239/28.274/28.310/0.171 ms


Install compiler

[root@lb01 ~]# yum install gcc
Loaded plugins: fastestmirror
Determining fastest mirrors
 * addons: mirror.averse.net
 * base: mirror.averse.net
 * extras: mirror.averse.net
 * updates: mirror.averse.net
addons                                                   |  951 B     00:00
base                                                     | 1.1 kB     00:00
base/primary                                             | 954 kB     00:08
base                                                                  2683/2683
extras                                                   | 2.1 kB     00:00
extras/primary_db                                        | 181 kB     00:01
updates                                                  | 1.9 kB     00:00
updates/primary_db                                       | 293 kB     00:02
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package gcc.i386 0:4.1.2-50.el5 set to be updated
--> Processing Dependency: cpp = 4.1.2-50.el5 for package: gcc
--> Processing Dependency: libgcc >= 4.1.2-50.el5 for package: gcc
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
--> Processing Dependency: libgomp >= 4.1.2-50.el5 for package: gcc
--> Running transaction check
---> Package cpp.i386 0:4.1.2-50.el5 set to be updated
---> Package glibc-devel.i386 0:2.5-58.el5_6.2 set to be updated
--> Processing Dependency: glibc-headers = 2.5-58.el5_6.2 for package: glibc-devel
--> Processing Dependency: glibc = 2.5-58.el5_6.2 for package: glibc-devel
--> Processing Dependency: glibc-headers for package: glibc-devel
---> Package libgcc.i386 0:4.1.2-50.el5 set to be updated
---> Package libgomp.i386 0:4.4.4-13.el5 set to be updated
--> Running transaction check
--> Processing Dependency: glibc = 2.5-49 for package: nscd
---> Package glibc.i686 0:2.5-58.el5_6.2 set to be updated
--> Processing Dependency: glibc-common = 2.5-58.el5_6.2 for package: glibc
---> Package glibc-headers.i386 0:2.5-58.el5_6.2 set to be updated
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
--> Processing Dependency: kernel-headers for package: glibc-headers
--> Running transaction check
---> Package glibc-common.i386 0:2.5-58.el5_6.2 set to be updated
---> Package kernel-headers.i386 0:2.6.18-238.9.1.el5 set to be updated
---> Package nscd.i386 0:2.5-58.el5_6.2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch       Version                    Repository     Size
================================================================================
Installing:
 gcc                  i386       4.1.2-50.el5               base          5.2 M
Installing for dependencies:
 cpp                  i386       4.1.2-50.el5               base          2.7 M
 glibc-devel          i386       2.5-58.el5_6.2             updates       2.0 M
 glibc-headers        i386       2.5-58.el5_6.2             updates       603 k
 kernel-headers       i386       2.6.18-238.9.1.el5         updates       1.1 M
 libgomp              i386       4.4.4-13.el5               base           72 k
Updating for dependencies:
 glibc                i686       2.5-58.el5_6.2             updates       5.3 M
 glibc-common         i386       2.5-58.el5_6.2             updates        16 M
 libgcc               i386       4.1.2-50.el5               base           96 k
 nscd                 i386       2.5-58.el5_6.2             updates       167 k

Transaction Summary
================================================================================
Install       6 Package(s)
Upgrade       4 Package(s)

Total download size: 34 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): libgomp-4.4.4-13.el5.i386.rpm                    |  72 kB     00:00
(2/10): libgcc-4.1.2-50.el5.i386.rpm                     |  96 kB     00:00
(3/10): nscd-2.5-58.el5_6.2.i386.rpm                     | 167 kB     00:01
(4/10): glibc-headers-2.5-58.el5_6.2.i386.rpm            | 603 kB     00:05
(5/10): kernel-headers-2.6.18-238.9.1.el5.i386.rpm       | 1.1 MB     00:09
(6/10): glibc-devel-2.5-58.el5_6.2.i386.rpm              | 2.0 MB     00:17
(7/10): cpp-4.1.2-50.el5.i386.rpm                        | 2.7 MB     00:23
(8/10): gcc-4.1.2-50.el5.i386.rpm                        | 5.2 MB     00:47
(9/10): glibc-2.5-58.el5_6.2.i686.rpm                    | 5.3 MB     00:51
(10/10): glibc-common-2.5-58.el5_6.2.i386.rpm            |  16 MB     02:30
--------------------------------------------------------------------------------
Total                                           112 kB/s |  34 MB     05:08
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
base/gpgkey                                              | 1.5 kB     00:00
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) " from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : libgcc                                                  1/14
  Updating       : glibc-common                                            2/14
  Installing     : kernel-headers                                          3/14
  Updating       : glibc                                                   4/14
  Installing     : glibc-headers                                           5/14
  Installing     : glibc-devel                                             6/14
  Installing     : cpp                                                     7/14
  Installing     : libgomp                                                 8/14
  Updating       : nscd                                                    9/14
  Installing     : gcc                                                    10/14
  Cleanup        : libgcc                                                 11/14
  Cleanup        : glibc-common                                           12/14
  Cleanup        : glibc                                                  13/14
  Cleanup        : nscd                                                   14/14

Installed:
  gcc.i386 0:4.1.2-50.el5

Dependency Installed:
  cpp.i386 0:4.1.2-50.el5              glibc-devel.i386 0:2.5-58.el5_6.2
  glibc-headers.i386 0:2.5-58.el5_6.2  kernel-headers.i386 0:2.6.18-238.9.1.el5
  libgomp.i386 0:4.4.4-13.el5

Dependency Updated:
  glibc.i686 0:2.5-58.el5_6.2         glibc-common.i386 0:2.5-58.el5_6.2
  libgcc.i386 0:4.1.2-50.el5          nscd.i386 0:2.5-58.el5_6.2

Complete!

Install SSL devel

[root@lb01 ~]# yum install openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.averse.net
 * base: mirror.averse.net
 * extras: mirror.averse.net
 * updates: mirror.averse.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.i386 0:0.9.8e-12.el5_5.7 set to be updated
--> Processing Dependency: openssl = 0.9.8e-12.el5_5.7 for package: openssl-devel
--> Processing Dependency: zlib-devel for package: openssl-devel
--> Processing Dependency: krb5-devel for package: openssl-devel
--> Running transaction check
---> Package krb5-devel.i386 0:1.6.1-55.el5_6.1 set to be updated
--> Processing Dependency: krb5-libs = 1.6.1-55.el5_6.1 for package: krb5-devel
--> Processing Dependency: libselinux-devel for package: krb5-devel
--> Processing Dependency: e2fsprogs-devel for package: krb5-devel
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel
---> Package openssl.i686 0:0.9.8e-12.el5_5.7 set to be updated
---> Package zlib-devel.i386 0:1.2.3-3 set to be updated
--> Running transaction check
---> Package e2fsprogs-devel.i386 0:1.39-23.el5_5.1 set to be updated
--> Processing Dependency: e2fsprogs-libs = 1.39-23.el5_5.1 for package: e2fsprogs-devel
---> Package keyutils-libs-devel.i386 0:1.2-1.el5 set to be updated
--> Processing Dependency: krb5-libs = 1.6.1-36.el5_4.1 for package: krb5-workstation
---> Package krb5-libs.i386 0:1.6.1-55.el5_6.1 set to be updated
---> Package libselinux-devel.i386 0:1.33.4-5.7.el5 set to be updated
--> Processing Dependency: libselinux = 1.33.4-5.7.el5 for package: libselinux-devel
--> Processing Dependency: libsepol-devel >= 1.15.2-1 for package: libselinux-devel
--> Running transaction check
--> Processing Dependency: e2fsprogs-libs = 1.39-23.el5 for package: e2fsprogs
---> Package e2fsprogs-libs.i386 0:1.39-23.el5_5.1 set to be updated
---> Package krb5-workstation.i386 0:1.6.1-55.el5_6.1 set to be updated
--> Processing Dependency: libselinux = 1.33.4-5.5.el5 for package: libselinux-utils
--> Processing Dependency: libselinux = 1.33.4-5.5.el5 for package: libselinux-python
---> Package libselinux.i386 0:1.33.4-5.7.el5 set to be updated
---> Package libsepol-devel.i386 0:1.15.2-3.el5 set to be updated
--> Running transaction check
---> Package e2fsprogs.i386 0:1.39-23.el5_5.1 set to be updated
---> Package libselinux-python.i386 0:1.33.4-5.7.el5 set to be updated
---> Package libselinux-utils.i386 0:1.33.4-5.7.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                  Arch      Version                  Repository    Size
================================================================================
Installing:
 openssl-devel            i386      0.9.8e-12.el5_5.7        base         1.9 M
Installing for dependencies:
 e2fsprogs-devel          i386      1.39-23.el5_5.1          base         569 k
 keyutils-libs-devel      i386      1.2-1.el5                base          27 k
 krb5-devel               i386      1.6.1-55.el5_6.1         updates      1.9 M
 libselinux-devel         i386      1.33.4-5.7.el5           base         144 k
 libsepol-devel           i386      1.15.2-3.el5             base         187 k
 zlib-devel               i386      1.2.3-3                  base         101 k
Updating for dependencies:
 e2fsprogs                i386      1.39-23.el5_5.1          base         977 k
 e2fsprogs-libs           i386      1.39-23.el5_5.1          base         118 k
 krb5-libs                i386      1.6.1-55.el5_6.1         updates      666 k
 krb5-workstation         i386      1.6.1-55.el5_6.1         updates      885 k
 libselinux               i386      1.33.4-5.7.el5           base          77 k
 libselinux-python        i386      1.33.4-5.7.el5           base          73 k
 libselinux-utils         i386      1.33.4-5.7.el5           base          55 k
 openssl                  i686      0.9.8e-12.el5_5.7        base         1.4 M

Transaction Summary
================================================================================
Install       7 Package(s)
Upgrade       8 Package(s)

Total download size: 8.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/15): keyutils-libs-devel-1.2-1.el5.i386.rpm           |  27 kB     00:00
(2/15): libselinux-utils-1.33.4-5.7.el5.i386.rpm         |  55 kB     00:00
(3/15): libselinux-python-1.33.4-5.7.el5.i386.rpm        |  73 kB     00:00
(4/15): libselinux-1.33.4-5.7.el5.i386.rpm               |  77 kB     00:00
(5/15): zlib-devel-1.2.3-3.i386.rpm                      | 101 kB     00:00
(6/15): e2fsprogs-libs-1.39-23.el5_5.1.i386.rpm          | 118 kB     00:00
(7/15): libselinux-devel-1.33.4-5.7.el5.i386.rpm         | 144 kB     00:01
(8/15): libsepol-devel-1.15.2-3.el5.i386.rpm             | 187 kB     00:01
(9/15): e2fsprogs-devel-1.39-23.el5_5.1.i386.rpm         | 569 kB     00:04
(10/15): krb5-libs-1.6.1-55.el5_6.1.i386.rpm             | 666 kB     00:05
(11/15): krb5-workstation-1.6.1-55.el5_6.1.i386.rpm      | 885 kB     00:07
(12/15): e2fsprogs-1.39-23.el5_5.1.i386.rpm              | 977 kB     00:08
(13/15): openssl-0.9.8e-12.el5_5.7.i686.rpm              | 1.4 MB     00:12
(14/15): krb5-devel-1.6.1-55.el5_6.1.i386.rpm            | 1.9 MB     00:16
(15/15): openssl-devel-0.9.8e-12.el5_5.7.i386.rpm        | 1.9 MB     00:16
--------------------------------------------------------------------------------
Total                                           116 kB/s | 8.9 MB     01:19
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : libsepol-devel                                          1/23
  Installing     : keyutils-libs-devel                                     2/23
  Installing     : zlib-devel                                              3/23
  Updating       : libselinux                                              4/23
  Updating       : e2fsprogs-libs                                          5/23
  Updating       : krb5-libs                                               6/23
  Updating       : openssl                                                 7/23
  Updating       : krb5-workstation                                        8/23
  Updating       : e2fsprogs                                               9/23
  Updating       : libselinux-python                                      10/23
  Updating       : libselinux-utils                                       11/23
  Installing     : e2fsprogs-devel                                        12/23
  Installing     : libselinux-devel                                       13/23
  Installing     : krb5-devel                                             14/23
  Installing     : openssl-devel                                          15/23
  Cleanup        : openssl                                                16/23
  Cleanup        : e2fsprogs-libs                                         17/23
  Cleanup        : libselinux-python                                      18/23
  Cleanup        : krb5-workstation                                       19/23
  Cleanup        : e2fsprogs                                              20/23
  Cleanup        : libselinux-utils                                       21/23
  Cleanup        : krb5-libs                                              22/23
  Cleanup        : libselinux                                             23/23

Installed:
  openssl-devel.i386 0:0.9.8e-12.el5_5.7

Dependency Installed:
  e2fsprogs-devel.i386 0:1.39-23.el5_5.1 keyutils-libs-devel.i386 0:1.2-1.el5
  krb5-devel.i386 0:1.6.1-55.el5_6.1     libselinux-devel.i386 0:1.33.4-5.7.el5
  libsepol-devel.i386 0:1.15.2-3.el5     zlib-devel.i386 0:1.2.3-3

Dependency Updated:
  e2fsprogs.i386 0:1.39-23.el5_5.1
  e2fsprogs-libs.i386 0:1.39-23.el5_5.1
  krb5-libs.i386 0:1.6.1-55.el5_6.1
  krb5-workstation.i386 0:1.6.1-55.el5_6.1
  libselinux.i386 0:1.33.4-5.7.el5
  libselinux-python.i386 0:1.33.4-5.7.el5
  libselinux-utils.i386 0:1.33.4-5.7.el5
  openssl.i686 0:0.9.8e-12.el5_5.7

Complete!

Install regular expression

[root@lb01 ~]# yum install pcre-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: mirror.averse.net
 * base: mirror.averse.net
 * extras: mirror.averse.net
 * updates: mirror.averse.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.i386 0:6.6-6.el5_6.1 set to be updated
--> Processing Dependency: pcre = 6.6-6.el5_6.1 for package: pcre-devel
--> Running transaction check
---> Package pcre.i386 0:6.6-6.el5_6.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch         Version                  Repository       Size
================================================================================
Installing:
 pcre-devel         i386         6.6-6.el5_6.1            updates         181 k
Updating for dependencies:
 pcre               i386         6.6-6.el5_6.1            updates         117 k

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)

Total download size: 298 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): pcre-6.6-6.el5_6.1.i386.rpm                       | 117 kB     00:00
(2/2): pcre-devel-6.6-6.el5_6.1.i386.rpm                 | 181 kB     00:01
--------------------------------------------------------------------------------
Total                                           101 kB/s | 298 kB     00:02
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : pcre                                                     1/3
  Installing     : pcre-devel                                               2/3
  Cleanup        : pcre                                                     3/3

Installed:
  pcre-devel.i386 0:6.6-6.el5_6.1

Dependency Updated:
  pcre.i386 0:6.6-6.el5_6.1

Complete!

Download HAProxy

[root@lb01 ~]# cd /tmp/
[root@lb01 tmp]# wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.15.tar.gz
--2011-04-15 15:13:29--  http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.15.tar.gz
Resolving haproxy.1wt.eu... 88.191.124.161
Connecting to haproxy.1wt.eu|88.191.124.161|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 812293 (793K) [application/x-gzip]
Saving to: `haproxy-1.4.15.tar.gz'

100%[======================================>] 812,293     7.83K/s   in 90s

2011-04-15 15:15:05 (8.79 KB/s) - `haproxy-1.4.15.tar.gz' saved [812293/812293]

Extract HAProxy

[root@lb01 tmp]# tar -xvf haproxy*.gz
[root@lb01 tmp]# cd haproxy-1.4.15
[root@lb01 haproxy-1.4.15]# make TARGET=linux26 CPU=i686

Copy HAProxy file to /user/bin and create or modify HAProxy config file

[root@lb01 haproxy-1.4.15]# cp haproxy /usr/bin

[root@lb01 haproxy-1.4.15]# nano /etc/haproxy.cfg

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #debug
        #quiet
        user haproxy
        group haproxy

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen webfarm 192.168.2.152:80
       mode http
       stats enable
       stats auth dgadmin:fuckuall
       balance roundrobin
       cookie JSESSIONID prefix
       option httpclose
       option forwardfor
       option httpchk HEAD /check.txt HTTP/1.0
       server webA 192.168.2.154:80 cookie A check
       server webB 192.168.2.155:80 cookie B check

Create or modify HAProxy startup

[root@lb01 haproxy-1.4.15]# /etc/init.d/haproxy"		

#!/bin/sh
#
# chkconfig: 2345 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Source function library.
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /etc/haproxy.cfg ] || exit 1

RETVAL=0

start() {
  /usr/sbin/haproxy -c -q -f /etc/haproxy.cfg
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file."
    return 1
  fi

  echo -n "Starting HAproxy: "
  daemon /usr/sbin/haproxy -D -f /etc/haproxy.cfg -p /var/run/haproxy.pid
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy
  return $RETVAL
}

stop() {
  echo -n "Shutting down HAproxy: "
  killproc haproxy -USR1
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy
  [ $RETVAL -eq 0 ] && rm -f /var/run/haproxy.pid
  return $RETVAL
}

restart() {
  /usr/sbin/haproxy -c -q -f /etc/haproxy.cfg
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with 'haproxy check'."
    return 1
  fi
  stop
  start
}

check() {
  /usr/sbin/haproxy -c -q -V -f /etc/haproxy.cfg
}

rhstatus() {
  status haproxy
}

condrestart() {
  [ -e /var/lock/subsys/haproxy ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    restart
    ;;
  condrestart)
    condrestart
    ;;
  status)
    rhstatus
    ;;
  check)
    check
    ;;
  *)
    echo $"Usage: haproxy {start|stop|restart|reload|condrestart|status|check}"
    RETVAL=1
esac

exit $RETVAL

Set HAProxy to start on boot (and start now)

[root@lb01]# chmod 755 /etc/init.d/haproxy

[root@lb01]#chkconfig --add haproxy
[root@lb01]#chkconfig haproxy on
[root@lb01]#service haproxy start

Download, extract and install nginx package

[root@lb01 tmp]# wget http://nginx.org/download/nginx-1.0.0.tar.gz
--2011-04-15 15:15:10--  http://nginx.org/download/nginx-1.0.0.tar.gz
Resolving nginx.org... 81.19.68.137
Connecting to nginx.org|81.19.68.137|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 654760 (639K) [application/octet-stream]
Saving to: `nginx-1.0.0.tar.gz'

100%[======================================>] 654,760     55.4K/s   in 11s

2011-04-15 15:15:26 (58.7 KB/s) - `nginx-1.0.0.tar.gz' saved [654760/654760]

[root@lb01 tmp]# tar -xvf nginx*.gz
[root@lb01 tmp]# cd nginx*
[root@lb01 nginx-1.0.0]#./configure
[root@lb01 nginx-1.0.0]# make
[root@lb01 nginx-1.0.0]# make install

Backup original nginx config file and create or modify config file

[root@lb01]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
[root@lb01]# nano /usr/local/nginx/conf/nginx.conf

worker_processes  2;
worker_rlimit_nofile 10000;
pid /var/run/nginx.pid;

events {
    worker_connections  4000;
    use epoll;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    keepalive_timeout  65;
    gzip  on;

    server {
        listen       80;
        server_name  gamecamp.co.id;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        location / {
            proxy_pass http://192.168.2.152:81/;
        }
    }

    server {
        listen       80 default;
        server_name_in_redirect off;
        rewrite      ^ http://gamecamp.co.id$request_uri;
    }
}

Create or modify /etc/init.d/nginx for start up or start on boot

[root@lb01]# nano /etc/init.d/nginx

#! /bin/sh
# chkconfig: 2345 87 13
# description: A HTTP and mail proxy server licensed under a \
#              2-clause BSD-like license.

# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author:       Ryan Norbauer
# Modified:     Geoffrey Grosenbach http://topfunky.com

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
  $DAEMON -c $CONFIGFILE || echo -n " already running"
}

d_stop() {
  kill -QUIT `cat $PIDFILE` || echo -n " not running"
}

d_reload() {
  kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        d_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC: $NAME"
        d_stop
        # One second might not be time enough for a daemon to stop,
        # if this happens, d_start will fail (and dpkg will break if
        # the package is being upgraded). Change the timeout if needed
        # be, or change d_stop to have start-stop-daemon use --retry.
        # Notice that using --retry slows down the shutdown process somewhat.
        sleep 1
        d_start
        echo "."
        ;;
  *)
          echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
          exit 3
        ;;
esac

exit 0

Add start up on boot and start now

[root@lb01]# chkconfig --add nginx
[root@lb01]# chkconfig nginx on
[root@lb01]# service nginx start

Leave a Reply

Your email address will not be published.