Linux搭建nginx集成環境

前言: Nginx是一個高性能的HTTP和反向代理服務器,本文只是粗略的記錄下配置,不作具體深刻研究java

環境:Centos6+nginx

            nginx-1.7.10.tar.gzweb

            g++、gcc、openssl-devel、pcre-devel和zlib-devel支持環境瀏覽器

一、在安裝nginx前,須要確保系統安裝了g++、gcc、openssl-devel、pcre-devel和zlib-devel軟件。緩存

    安裝必須軟件:bash

#    yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel服務器

*:經過yum的方式自動安裝所需環境軟件tcp

二、檢查系統安裝的Nginx:memcached

#    find / -name nginx性能

*:yum remove nginx

三、解壓nginx安裝包到指定目錄:

#    tar -zxvf nginx-1.7.10.tar.gz -C /5108/java/

四、進入到/5108/java/nginx-1.7.10目錄下,安裝nginx到指定目錄:

#    ./configure --prefix=/5108/java/nginx

#     make

#    make install

五、修改防火牆配置:

#    vi  /etc/sysconfig/iptables

#添加配置項,過濾80端口
#    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#重啓防火牆
#    service iptables restart

六、nginx啓動:

進入sbin目錄下#    ./nginx

    重啓:#    ./nginx -s reload
    關閉:#    ./nginx -s stop

七、設置nginx開機啓動:

1)、建立nginx腳本,並放到/etc/init.d/nginx目錄下,腳本內容以下:

            

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/5108/java/nginx/sbin/nginx
nginx_config=/5108/java/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid

RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

*:修改其中紅色字體爲本身環境中的路徑

2)、爲nginx腳本添加權限:

#    chmod a+x /etc/init.d/nginx

    *:a+x 爲所賦權限,如"777"

3)、添加nginx服務:

#    chkconfig --add nginx
#    chkconfig nginx on

4)、測試

#    service nginx start    #啓動
#    service nginx stop    #中止
#    service nginx reload    #重啓

*:瀏覽器中輸入ip便可測試是否成功安裝及啓動。

到此,nginx的安裝基本結束,後續再跟進nginx+memcached設置緩存共享和nginx策略基本配置詳解等...

相關文章
相關標籤/搜索