当前位置:首页 > 资讯 > 热门博客 > 正文

CentOS 6.3 编译安装Nginx 1.2.4

发表于: 2012-11-05   作者:ydt619   来源:转载   浏览次数:
摘要:  1.         安装nginx相关的依赖包yum-yinstallgccopenssl-develpcre-develzlib-develpcre-devellibtoolgcc-c++ 2.        下载安装nginxwgethttp://nginx.org/download/nginx-1.2.4.tar.gztarzxvfnginx-1.2.4.tar.gzcdnginx-1.

 1.          安装nginx相关的依赖包

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

 

2.         下载安装nginx

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

tar zxvf nginx-1.2.4.tar.gz

cd nginx-1.2.4

./configure --help |more     #查看编译的参数选项

useradd www

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

make && make install

 

 

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

 

 

CentOS 6.3 编译安装Nginx 1.2.4

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
说明: 操作系统:CentOS 6.3 32位 系统安装教程:CentOS 6.3安装(超级详细图解教程) 准备篇: 一、
最近一直在安装nginx,总是有一些问题。困扰了我很久,也查找了很多资料。最后终于搞定了,安装好了
GCC5.1.0下载地址:http://ftp.gnu.org/gnu/gcc/gcc-5.1.0/ gmp、mpfr、mpc下载地址:ftp://gcc.gnu
本文主要简单介绍Nginx特点及在centos 6.6 x86_64系统环境下编译安装轻量级http服务器nginx的方法
环境 服务器:192.168.10.181 系统:CentOS 6.0 Nginx版本:1.0.8 安装过程 1、打开终端命令窗口(
一、环境 CentOS: CentOS-6.3-x86_64-minimal.iso 虚拟机:VirtualBox-4.1.12 主机:Windows 7 64bi
最近我一直在倒腾centos6.3。反复安装数次今晚上终于进入了。我的情况是这样:XP本地硬盘(120G),U
简介: 环境:虚拟机+centos6.6 Cmake下载地址:http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.
Nginx官方站点 http://nginx.org/cn/ tengine 淘宝基于nginx二次开发 http://tengine.taobao.org/ n
Linux操作系统:CentOS 6.3 1:下载:当前mysql版本到了5.6.10 下载地址:http://dev.mysql.com/dow
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号