linux 安裝 nginx 及反向代理配置

Nginx ("engine x") 是一個高性能的HTTP反向代理服務,如下爲Linux centos平臺下安裝nginx並配置反向代理的過程(採用源碼安裝的方式)javascript

一:安裝編譯環境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
make
make install
sudo make install
查看nginx啓動和配置目錄 whereis nginx

 

注:sbin-path(啓動文件路徑)css

      conf-path(配置文件路徑)java

       pid-pathpid文件,剛安裝完默認沒有,只有啓動nginx後纔有 node

四:啓動nginx

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

五.配置反向代理 指向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不會被壓縮

  

未完待續。。。

相關文章
相關標籤/搜索