CentOS 6.3 編譯安裝Nginx 1.2.4

 1.          安裝nginx相關的依賴包javascript

yum -y install gcc openssl-devel pcre-devel zlib-devel pcre-devel libtool gcc-c++ php

 

2.         下載安裝nginx css

wget http://nginx.org/download/nginx-1.2.4.tar.gz html

tar zxvf nginx-1.2.4.tar.gz java

cd nginx-1.2.4 node

./configure --help |more     #查看編譯的參數選項 nginx

useradd www c++

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module app

make && make install tcp

 

 

3.         設定nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

 

user  www www;

worker_processes 8;

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

pid        /var/run/nginx.pid;

error_log  /usr/local/nginx/logs/error.log  crit;

worker_rlimit_nofile 65535;

events

{

        use epoll;

        worker_connections 65535;

}

 

http

{

        include       mime.types;

        default_type  application/octet-stream;

 

        server_names_hash_bucket_size 128;

 

        keepalive_timeout 0;

        client_header_buffer_size    16k;

        client_max_body_size         32m;

        large_client_header_buffers  8 1024k;

        client_header_timeout  3m;

        client_body_timeout    3m;

        send_timeout           3m;

        connection_pool_size        256;

        request_pool_size        4k;

        output_buffers   16 128k;

        postpone_output  1460;

        fastcgi_connect_timeout 300;

        fastcgi_send_timeout 300;

        fastcgi_read_timeout 300;

        fastcgi_buffer_size 128k;

        fastcgi_buffers 16 256k;

        fastcgi_busy_buffers_size 512k;

        fastcgi_temp_file_write_size 512k;

        fastcgi_temp_path /dev/shm;

 

        open_file_cache max=65536 inactive=20s;

        open_file_cache_min_uses 1;

        open_file_cache_valid 30s;

 

        tcp_nodelay on;

        gzip on;

        gzip_min_length  1k;

        gzip_buffers     16 1024k;

        gzip_http_version 1.1;

        gzip_types       text/plain application/x-javascript text/css application/xml;

        log_format  access  '$remote_addr - $remote_user [$time_local] "GET http://$host$request_uri $server_protocol" '

        '$status $body_bytes_sent "$http_referer" '

        '"$http_user_agent" $http_x_forwarded_for';

        server

       {

          listen 80;

          server_name _;

          location ~ / {

             deny all;

          }

       }

       include vhosts/*.conf;

}

 

 

 

vi /usr/local/nginx/conf/vhosts/prefect.conf

 

server

{

listen 80 default;

server_name www.prefect.com;

root /data/httpd/www.prefect.com;

index index.html index.php index.htm;

 

error_page 404 /index.html;

error_page 502 /index.html;

 

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

        {

expires      30d;

        }

 

location ~ .*\.(js|css)?$

        {

expires      1h;

        }

 

access_log /usr/local/nginx/logs/access.log;

}

 

4.         設定nginx啓動文件

vi /etc/init.d/nginx

 

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/var/run/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 /var/run/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

 

5.          修改iptables後啓動Nginx

/usr/local/nginx/sbin/nginx –t   #測試配置文件格式

/etc/init.d/nginx start

相關文章
相關標籤/搜索