Nginx

(“engine x”) 是一个高性能的HTTP和反向代理服务器,以下为Linux centos平台下安装nginx并配置反向代理的过程(采用源码安装的方式) 一:安装编译环境gcc g++ 和make(用于编译源代码成可执行文件) 1yum install gcc gcc-c++ 2 yum -y install gcc automake autoconf libtool make 二:安装pcre (nginx rewrite依赖pcre库)zlib(用于gzip压缩) 1.安装pcre cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz tar -zxvf pcre-8.34.tar.gzcd pcre-8.34 ./configure make make install    2.安装zlib cd /usr/local/src wget http://zlib.net/zlib-1.2.8.tar.gz tar -zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8 ./configure make make install 3.安装openssl wget http://www.openssl.org/source/openssl-1.0.1t.tar.gz tar -zxvf openssl-1.0.1t.tar.gz ./config shared –prefix=/usr/local –openssldir=/usr/local/ssl make depend make sudo make install    三.安装nginx cd /usr/local/src wget http://nginx.org/download/nginx-1.10.1.tar.gz tar -zxvf nginx-1.10.1.tar.gz cd nginx-1.10.1 ./configure –sbin-path=/usr/local/nginx/sbin –conf-path=/usr/local/nginx/conf/nginx.conf –pid-path=/usr/local/nginx/nginx.pid –with-http_ssl_module –with-pcre=/usr/local/src/pcre-8.39 –with-zlib=/usr/local/src/zlib-1.2.8 –with-openssl=/usr/local/src/openssl-1.0.1t make make install sudo make install   注:sbin-path(启动文件路径) conf-path(配置文件路径) pid-path(pid文件,刚安装完默认没有,只有启动nginx后才有)  四:启动nginx Cd /usr/local/nginx/sbin 1.启动 ./nginx 2.重启 ./nginx -s reload 五.配置反向代理 指向node(其中node监听127.0.0.1:3000) Cd /usr/local/nginx/conf Vim nginx.conf 其中server选项配置如下 lerver{ listen 80; charset utf-8; location / { proxy_pass http://127.0.0.1:3000; } }    lerver{ listen 80; charset utf-8; location / { proxy_pass http://127.0.0.1:3000; } } 六.开启gizp压缩 http选项下 http选项下 gzip on; gzip_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types application/javascript text/javascript text/plain application/x-javascript text/css application/xml; gzip_vary on; 注意:gzip_types必须加上application/javascript 否则js不会被压缩    未完待续。。。


Nginx
http://example.com/2017-03-27 nginx/
作者
csorz
发布于
2017年3月27日
许可协议