nginx1.3.6 的简单配置和启动脚本

(1) nginx信息
root@ubuntu:/usr/local/nginx/sbin# ./nginx -V
nginx version: nginx/1.3.6
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
TLS SNI support enabled
configure arguments: --add-module=/home/zhangbin/mserver/nginx/nginx_mod_h264_streaming-2.2.7 --with-pcre=/home/zhangbin/mserver/nginx/pcre-8.31 --with-pcre-jit --with-zlib=/home/zhangbin/mserver/nginx/zlib/1.2.3 --prefix=/usr/local/nginx --with-http_flv_module --with-http_stub_status_module --with-http_mp4_module --add-module=/home/zhangbin/mserver/nginx/nginx-accesskey-2.0.3 --with-http_ssl_module --with-openssl=/home/zhangbin/mserver/nginx/openssl-1.0.1c --with-cc-opt=-O3
root@ubuntu:/usr/local/nginx/sbin# 


(2)我的配置脚本

root@ubuntu:/usr/local/nginx/conf# gedit nginx.conf

#user  videoapp video;
#user nobody;
worker_processes  8;


error_log  /usr/local/nginx/logs/error.log;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


#pid        logs/nginx.pid;
pid        /usr/local/nginx/logs/nginx.pid;




events {
##轮训方式
##epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
    use epoll;
##允许的最大连接数
##单个后台worker process进程的最大并发链接数
    worker_connections  1024;
}




http {
    include       mime.types;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;
    access_log  /usr/local/nginx/logs/access.log main;
    #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,
    #必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile        on;
    tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    gzip  on;


    server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;
        charset  gb2312,utf-8;


        access_log  logs/server_name_localhost.access.log  main;


        location / {
            root   /usr/local/nginx/html/video_files/;
            index  index.html index.htm index.php;
        }


        error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}


        location ~ \.mp4$ {
            mp4;
        }
        location ~ \.flv {
            flv;
        }
    }




    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;


    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}




    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;


    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;


    #    ssl_session_timeout  5m;


    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;


    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


}


(3)加入一个控制nginx的启动脚本,据说ubuntu apt安装的nginx是有这个脚本的。


zhangbin@ubuntu:~$  gedit /etc/init.d/nginx


略加修改:


#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#

# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid


# Source function library.
#. /etc/rc.d/init.d/functions


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


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


nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)


NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"


lockfile=/var/lock/subsys/nginx


start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
     daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}


stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}


restart() {
    configtest || return $?
    stop
    start
}


reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}


force_reload() {
    restart
}


configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}


rh_status() {
    status $prog
}


rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

(4)
以上只是初步配置,
关于nginx的其他配置,包括服务器、流媒体、停止启动后续还将继续在是使用中与大家分享。

你可能感兴趣的:(nginx,server,ssl,ubuntu,Module,networking)