linux(centos6.6) 下安装,配置nginx, 及开机自启动

linux:centos 6.6 x64

nginx:1.7.8

 

1.安装一下软件:

  1. yum -y install pcre*
  1. yum -y install openssl*
  # pcre 重定向支持

 #openssl https协议支持


2.下载nginx (1.7.8)

  1. wget http://nginx.org/download/nginx-1.7.8.tar.gz

3.解压编译,安装


tar -zxvf nginx-1.7.8.tar.gz


cd nginx-1.7.8


./configure --prefix=/usr/local/nginx

./configure --with-http_ssl_module

./configure --with-http_spdy_module

./configure --with-http_stub_status_module

./configure --with-pcre


安装

make && make install

启动

cd /usr/local/nginx/sbin/nginx

./nginx


5.本机外机器访问需要改动防火墙配置可采取一下一种(1.关闭防火墙,2.防火墙开放80端口)

5.1 关闭防火墙服务

service iptables stop


5.2 

开放80端口方式一


编辑配置文件:
vim /etc/sysconfig/iptables

添加开放80端口配置
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙服务
service iptables restart

开放80端口方式二


/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

/etc/rc.d/init.d/iptables save

/etc/init.d/iptables restart


5.3 关闭端口

对应上面两种开启方式 将 ACCEPT 改成 DROP 后重启防火墙即可.


5.4 查看防火墙端口状态

/ect/init.d/iptables status


查看80端口使用情况:

lsof -i:80



nginx 开机自启动配置:


1.在 /etc/init.d/ 目录下创建nginx文件 其中nginxd ,nginx_config, nginx_pid 的值根据具体目录配置,文件内容如下:

#!/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=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/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 /usr/local/nginx/logs/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.设置文件的访问权限:
chmod a+x /etc/init.d/nginx (a+x参数表示 ==> all user can execute  所有用户可执行)

3.最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
vim /etc/rc.local
添加
/etc/init.d/nginx start 
:wq
重启生效


注意细节:如果nginx文件是在windows中编辑生成的 则在vim 编辑器中执行以下命令 set ff? 查看是否是dos 如果是则再执行 set ff=unix 即可  否则启动nginx 时会报错.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值