nginx1.0.14安装

groupadd web
useradd -g web web -M -s /sbin/nologin
1、wget http://nginx.org/download/nginx-1.0.14.tar.gz
2、tar xzvf nginx-1.0.14.tar.gz
3、cd nginx-1.0.14/src/core
   vi nginx.h
修改以下三项内容,隐藏nginx版本
   #define nginx_version      0000000
   #define NGINX_VERSION      "0000"
   #define NGINX_VER          "apache/" NGINX_VERSION
4、安装pcre库
   wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz
   tar pcre-8.13.tar.gz
   cd pcre-8.13
   ./configure
   make &&make install
5、./configure --prefix=/opt/nginx \
--sbin-path=/opt/nginx/sbin/nginx \
--conf-path=/opt/nginx/conf/nginx.conf \
--pid-path=/var/run/nginx/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-proxy-temp-path=/opt/nginx/temp/proxy \
--http-fastcgi-temp-path=/opt/nginx/temp/fcgi \
--lock-path=/var/run/nginx/nginx.lock \   
--with-http_ssl_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_flv_module \
--with-debug \
--user=web --group=web \
--with-pcre


6、

mkdir /var/log/nginx

mkdir /var/run/nginx

mkdir /opt/nginx/temp

mkdir /var/spool/nginx

chown -R web.web /var/log/nginx

chown -R web.web /var/run/nginx

chown -R web.web /opt/nginx/temp

chown -R web.web /var/spool/nginx

7、

/opt/nginx/sbin/nginx -t测试一下是否可以正常启动。

/opt/nginx/sbin/nginx启动nginx

8、vi /opt/nginx/conf/nginx.conf

user  web;
worker_processes  4;
#worker_rlimit_nofile 4096;

#error_log  logs/error.log;
error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx/nginx.pid;


events {
                use epoll;
        worker_connections 20480;
}


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"'

                log_format combined     '$remote_addr - $remote_user [$time_local] $request '
                                                 '"$status" $body_bytes_sent "$http_referer" '
                                                 '"$http_user_agent" "$http_host" "$request_time" "$http_x_forwarded_for" "$http_via" "$gzip_ratio"';

#               access_log  /var/log/nginx/access.log  combined;

                access_log  off;
                sendfile        on;
                tcp_nopush      on;

                #keepalive_timeout  0;
                keepalive_timeout  60;
                tcp_nodelay        on;
       
                client_header_buffer_size  4k;
                large_client_header_buffers 4 4k;
        client_body_temp_path      /var/spool/nginx/client 1 2;
        client_max_body_size       10m;
        client_body_buffer_size    128k;       
        #--http-fastcgi-temp-path  /var/spool/nginx/fcgi;

                proxy_temp_path            /var/spool/nginx/proxy;
                proxy_connect_timeout      300;
                proxy_send_timeout         300;
                proxy_read_timeout         300;
                proxy_buffer_size          16k;
                proxy_buffers              4 32k;
                proxy_busy_buffers_size    64k;
                proxy_temp_file_write_size 64k;         
               #fastcgi
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                fastcgi_buffer_size 64k;
                fastcgi_buffers 4 64k;
                fastcgi_busy_buffers_size 128k;
                fastcgi_temp_file_write_size 128k;
                #open_file
                open_file_cache max=20480 inactive=20s;
                open_file_cache_min_uses 1;
                open_file_cache_valid  30s;


                gzip  on;
                gzip_min_length  1100;
                gzip_buffers     4 8k;
                gzip_types       text/plain  text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        gzip_comp_level  2;
                gzip_vary  on;   
                index  index.htm index.py;


        server_names_hash_bucket_size 64;

                limit_zone account $binary_remote_addr 10m;
    include upstream.conf;#配置负载均衡及反向代理
    include conf/vhosts/vhost-www.conf;#配置虚拟机
 

nginx自启动脚本
vi /etc/rc.d/init.d/nginx.sh
#!/bin/bash
#  (Linux  ) /etc/rc.d/init.d/nginx.sh, symlinked from rc3.d/S95nginx
#  (FreeBSD) /usr/local/etc/rc.d/nginx.sh


if [ ! -e /var/run/nginx ]; then
    mkdir -p /var/run/nginx
    chown -R web.web /var/run/nginx
    chmod a+wt /var/run/nginx
fi

/opt/nginx/sbin/nginxctl start

# EOF: nginx.sh

nginx控制脚本
vi nginxctl
#!/bin/bash

[ -x /opt/nginx/sbin/nginx ] || exit 0

RETVAL=0

prog="nginx"

start() {
    # Start daemons.
    if [ -e /opt/nginx/conf/nginx.conf ] ; then

        echo -n $"Starting $prog: "
        ulimit -n 20480         
        # this number 2048 remember write it into nginx.conf like below
        # events {
        # worker_connections 2048;
        # }

        /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf &
        RETVAL=$?
        [ $RETVAL -eq 0 ] && {
            touch /var/lock/subsys/$prog
        }
        echo success $"$prog"
    else
        RETVAL=1
fi
return $RETVAL
}

stop() {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    killall nginx
    #kill -3 `cat /var/run/nginx/nginx.pid 2>/dev/null`
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

case "$1" in

start )
    start
    ;;

stop )
    stop
    ;;

reconfigure )
    if [ -f /var/lock/subsys/$prog ]; then
        kill -1 `cat /var/run/nginx/nginx.pid 2>/dev/null`
        RETVAL=$?
    fi
    ;;

configtest )
    /opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
    RETVAL=$?
    ;;

*)
echo $"Usage: $0 {start|stop|reconfigure|configtest}"
exit 1

esac

exit $RETVAL

#EOF: nginxctl.sh