Nginx部署
1、环境准备
[root@nginx-master~]# yum install pcre* openssl*
注明:
pcre ---> 支持rewrite功能
openssl* ---> 需要ssl的支持
2、安装nginx
[root@nginx-mastertools]# tar zxf nginx-1.6.3.tar.gz
[root@nginx-master nginx-1.6.3]# ./configure\
>--prefix=/usr/local/nginx \
>--with-http_ssl_module \ 支持https
>--with-http_spdy_module \
>--with-http_stub_status_module \ 支持nginx状态查询
>--with-pcre 支持rewrite重写
[root@nginx-masternginx-1.6.3]# make
[root@nginx-masternginx-1.6.3]# make install
3、启动nginx
[root@nginx-master ~]# /usr/local/nginx/sbin/nginx
[root@nginx-master ~]# netstat -ntulp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29900/nginx
4、nginx关闭
[root@nginx-master ~]# /usr/local/nginx/sbin/nginx -s stop
nginx reload(重置出错)
[root@nginx-master ~]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] open()"/usr/local/nginx/logs/nginx.pid" failed (2: No such file ordirectory)
解决办法:
[root@nginx-master ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5、nginx启动脚本 (此版本有个bug,脚本名不能含有“nginx”,待完善。。。)
#!/bin/env python
# -*- coding:utf-8 -*-
'''
Created on 2015-12-28
@author: shaw
'''
import sys,os
from time import sleep
nginxcmd='/usr/local/nginx/sbin/nginx'
def slow(msg1,text,msg2):
print msg1,
for i in text:
print i,
sys.stdout.flush()
sleep(0.8)
print msg2,
return '.'
def checkprocess():
global Nginxprocess
Nginxprocess = os.system('ps -ef | grep nginx | grep -v grep >/dev/null') # bug就在这里
def judge():
checkprocess()
if Nginxprocess == 0:
return 'started'
if Nginxprocess != 0:
return 'stoped'
def start():
if judge() == 'stoped':
os.system(nginxcmd)
checkprocess()
if Nginxprocess == 0:
slow('Starting Nginx','...','SUCCESS!')
else:
print '\033[33;2m#INFO\033[0m: Nginx server has already started.'
def stop():
if judge() == 'started':
os.system('%s -s stop'% nginxcmd)
checkprocess()
if Nginxprocess != 0:
slow('Stoping Nginx','...','SUCCESS!')
else:
print '\033[33;2m#INFO\033[0m: Nginx server has already stoped.'
def reload():
judge()
if judge() == 'started':
os.system('%s -s reload'% nginxcmd)
try:
command = sys.argv[1]
except IndexError:
print "\033[31;2m#ERROR\033[0m: you must given one arguement,such as: httpd.py start|stop|reload"
else:
if command == 'start':
start()
elif command == 'stop':
stop()
elif command == 'reload':
reload()
else:
print '\033[31;2m### Usage\033[0m: nginx.py {start|stop|reload} [ Nginx server options ]'

















