`
tianshibaijia
  • 浏览: 1126163 次
文章分类
社区版块
存档分类
最新评论

nginx 安装,配置

 
阅读更多

一般编译nginx时,都要先安装pcre、zlib等外部支持程序,然后编译安装nginx时指定这些外部支持程序的位置,这样nginx在每次启动的时候,就会去动态加载这些东西了。

下面介绍的是另一种方式,即将这些程序编译到nginx里面去,这样nginx启动时就不会采用动态加载的方式去load。从古谱中可获知,这种方式会比动态加载有更高的效率。
需要下载的东西:
1. wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz
2. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.bz2
3. wget http://www.zlib.net/zlib-1.2.5.tar.bz2
4. wget http://nginx.org/download/nginx-0.8.52.tar.gz

把这些都解压缩后,就会有:
1. openssl-0.9.8l
2. pcre-8.00
3. zlib-1.2.3
4. nginx-0.8.30

这几个目录,我把它们都放在/homr/software/里,按原先的方式,需要进openssl、pcre、zlib目录里去编译安装它们,现在不用了,直接进nginx目录。

安装build.sh

#set nginx root path
HOME=/home/raycloud/
NGINX_HOME=$HOME/nginx
NGINX_SOURCE=$HOME/soft/nginx
#install path
install=$NGINX_HOME
#pcre source
pcre=$NGINX_SOURCE/pcre
#zlib source path
zlib=$NGINX_SOURCE/zlib
#openssl source path
openssl=$NGINX_SOURCE/openssl
#cpu type
cpu=pentium4

#user
user=`whoami`

#group
group=anygroup

if [ ! -d $install ] ; then
mkdir -p $install
fi
./configure --user=$user --group=$group --prefix=$install --with-http_gzip_static_module --with-pcre=$pcre --with-zlib=$zlib --with-http_ssl_module --with-openssl=$openssl


把上面的shell拷贝成sh可安装完成,这种方式安装的时间会较长,因为需要先编译外部程序,值得注意的是,make时不能加-j多进程方式,只能用单进程make,不然没法通过。如果你的应用不需要openssl,那么可以不下载openssl并在configure时将其去掉。另外,nginx的 google_perftools_module还不能用这种方式编译进去,所以还是要先在外部安装google_perftools。

nginx.conf配置

user nobody;
worker_processes 4;

error_log /home/raycloud/nginx/error/nginx_error.log crit;
pid /home/raycloud/nginx/error/nginx.pid;

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;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 90;

tcp_nodelay on;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

server {
listen 80;
server_name yourdoamin;

charset utf-8;


#access_log logs/host.access.log main;

access_log off;

location ~ (\.shtm)$ {
proxy_pass http://127.0.0.1:8088;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 1800; //这里是浏览器和NGINX通讯的超时时间。如果请求比较长可以稍微调大一些。
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}

pcre编译进去支持正则,如下

rewrite ^/img/freetemplate/template([0-9]+)/([0-9]+)/(.+)$ /img/freetemplate/template$1/$3 last;

location ~* ^.+.(jpg|jpeg|gif|png|ico|css|html|xml|cfm|cfc|afp|asp|lasso|pl|py|txt|fla|swf)$ {
root /test/WebRoot;
expires 1d;
}

location ~* ^.+.(js|css)$ {
root /test/WebRoot;
expires 2h;
}

}

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics