当前位置:首页 > 资讯 > 开源软件 > 正文

centos 6.5上编译安装nginx

发表于: 2015-12-22   作者:hiwill   来源:转载   浏览:
摘要: 平台:Centos6.5x86_641,安装基本库yuminstall-ygccgcc-c++autoconfautomake2,安装支持模块yuminstall-yzlibzlib-developensslopenssl-develpcrepcre-devel3,编译安装nginxwgethttp://nginx.org/download/nginx-1.9.9.tar.gztarzxvfngi

平台:Centos 6.5 x86_64

1,安装基本库

yum install -y gcc gcc-c++ autoconf automake

2,安装支持模块

yum install -y zlib zlib-devel openssl openssl-devel pcre pcre-devel

3,编译安装nginx

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

tar zxvf nginx-1.9.9.tar.gz

cd nginx-1.9.9

./configure

make 

make install


启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf


停止

kill - QUIT '/usr/local/webserver/nginx/logs/nginx.pid'

强制停止

pkill -9 nginx


4,特性配置

4.1 nginx压缩输出配置

nginx.conf下

http{...}中

gzip on;

gzip_min_length 1k;

gzip_buffers     4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

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

gzip_vary on;


4.2自动列出目录配置

在虚拟主机location / {

    autoindex on;

    autoindex_exact_size on;

    autoindex_localtime on;

}


4.3浏览器本地图片、js、css文件缓存配置

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

{

    expires 7d;

}

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

{

    expires 1h;

}


4.4目录自动加斜线

if (-d $request_filename){

       rewrite ^/(.*)([^/])$ http://$host/$1/$2/ permanent;

}


配置完nginx 后检查语法正确与否

/usr/local/webserver/nginx/sbin/nginx -t

查看nginx主进程号

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

5.优化内核参数

vi /etc/sysctl.conf


net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog = 32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_tw_recycle =1

#net.ipv4.tcp_tw_len =1

net.ipv4.tcp_tw_reuse =1


#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024 65535



centos 6.5上编译安装nginx

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号