Nginx ("engine x") 是一個高性能的HTTP和反向代理服務器,如下爲Linux centos平臺下安裝nginx並配置反向代理的過程(採用源碼安裝的方式)javascript
1yum install gcc gcc-c++ 2 yum -y install gcc automake autoconf libtool make
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
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
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
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 make make install sudo make install
查看nginx啓動和配置目錄 whereis nginx
注:sbin-path(啓動文件路徑)css
conf-path(配置文件路徑)java
pid-path(pid文件,剛安裝完默認沒有,只有啓動nginx後纔有) node
Cd /usr/local/nginx/sbinnginx
1.啓動 ./nginxc++
2.重啓 ./nginx -s reloadcentos
啓動的時候報錯app
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory性能
解決方法:spa
ln -s /usr/local/lib/libpcre.so.1 /lib64
32位系統則:
ln -s /usr/local/lib/libpcre.so.1 /lib
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;
}
}
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不會被壓縮