nginx是一個web網站常用的高性能http和反向代理伺服器,其具有較好的并發能力,被網易、百度、騰訊、新浪等網站廣泛使用。
正向代理:代理用戶端,替用戶端收發請求,使真實的用戶端對伺服器不可見。如圖所示,proxy和client同屬于一個網絡,對server透明
反向代理:代理伺服器,提伺服器收發請求,使真實的伺服器對用戶端不可見。如圖所示,proxy和server同屬于一個網絡,對client透明

實際上proxy都是代為收發請求和響應,隻是在結構上左右換了下,是以一個叫正向代理,另一個叫反向代理。
如下圖所示:nginx作為反向代理伺服器接收來自用戶端的http請求,然後将請求轉發給内部網絡的web伺服器,同時接收來自web伺服器的response結果,并傳回給用戶端。此時nginx代理伺服器對外展現為一個伺服器。
(1)負載均衡。nginx可以将來自用戶端的請求均衡的分發到web伺服器叢集中的不同機器上進行處理,平衡叢集中各個伺服器的壓力。這對于大通路量的web網站來說,是需要的。
(2)安全保障。用戶端直接通路的不是提供内容的web伺服器,為保護網站伺服器提供了一層屏障,有利于保護網站的安全。
(3)加速web請求。nginx可以配置緩存,存儲真實web伺服器的某些資源和響應,減輕真實伺服器的壓力,同時加速web請求
二、 nginx-1.9.7 編譯安裝
下載下傳位址: http://nginx.org/download/nginx-1.9.7.tar.gz
補充: 安裝 nginx之前,需要先安裝一些依賴包:gcc、pcre、zlib
a、nginx gzip子產品需要zlib庫
b、nginx rewrite子產品需要pcre庫
c、nginx ssl子產品需要openssl庫
1、安裝必要依賴包
[root@mysql03 ~]# yum install -y pcre pcre-devel
centos 6.7 配置 yum 本地源 連結參考: http://blog.csdn.net/zhang123456456/article/details/56690945
2、 Nginx安裝
[root@mysql03 ~]# ll nginx-1.9.7.tar.gz
-rw-r--r--. 1 root root 885562 Jun 14 21:46 nginx-1.9.7.tar.gz
[root@mysql03 ~]# tar zxvf nginx-1.9.7.tar.gz
[root@mysql03 ~]# cd nginx-1.9.7
-- 配置nginx安裝選項
[root@mysql03 nginx-1.9.7]# ./configure --prefix=/usr/local/nginx
說明: 配置完畢後可以看到一個配置概要,概要中的5項必須都有了相應的庫支援
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
##如果想要安裝openssl子產品,安裝時需指定 ./configure --prefix=/usr/local/nginx --with-openssl=/root/openssl-1.0.2d ##
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
-- 安裝nginx
[root@mysql03 nginx-1.9.7]# make && make install
3、 檢查安裝是否正常
[root@mysql03 nginx-1.9.7]# cd /usr/local/nginx
[root@mysql03 nginx]# ll
total 16
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 conf
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 html
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 logs
drwxr-xr-x. 2 root root 4096 Jun 14 22:14 sbin
-- 啟動
[root@mysql03 nginx]# ./sbin/nginx #如果不能正常啟動,可能是端口占用
[root@mysql03 nginx]# ps -ef|grep nginx
root 5212 1 0 22:17 ? 00:00:00 nginx: master process ./sbin/nginx
nobody 5213 5212 0 22:17 ? 00:00:00 nginx: worker process
root 5228 2359 0 22:20 pts/0 00:00:00 grep nginx
-- 通路
浏覽器輸入: http://10.219.24.26/ #ip換成自己的ip
看到以下頁面内容,一切正常。
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
-- 關閉
[root@mysql03 nginx]# ./sbin/nginx -s stop
root 5241 2359 0 22:25 pts/0 00:00:00 grep nginx
說明: http://www.cnblogs.com/zengkefu/p/5814793.html 部分參考,感謝作者
文章可以轉載,必須以連結形式标明出處。
本文轉自 張沖andy 部落格園部落格,原文連結: http://www.cnblogs.com/andy6/p/7008795.html ,如需轉載請自行聯系原作者