Nginx入門筆記_第一篇

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重寫

[[email protected]]# make

[[email protected]]# 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

    wKiom1bXwOvRzvsDAABoJLnDCvc606.png

4nginx關閉

[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

5nginx啓動腳本 (此版本有個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 ]'


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章