Linux下安裝Nginx詳細圖解教程
什么是Nginx?
Nginx?("engine?x")?是一個高性能的?HTTP?和?反向代理?服務器,也是一個?IMAP/POP3/SMTP?代理服務器,在高連接并發的情況下Nginx?是?Apache?服務器不錯的替代品.其特點是占有內存少,并發能力強,事實上nginx的并發能力確實在同類型的網頁服務器中表現較好.目前中國大陸使用nginx網站用戶有:新浪、網易、?騰訊,另外知名的微網志Plurk也使用nginx。?
Nginx?作為?負載均衡?服務器:?
Nginx?既可以在內部直接支持?Rails?和?PHP?程序對外進行服務,也可以支持作為?HTTP?代理服務器對外進行服務。?Nginx?采用?C?進行編寫,?不論是系統資源開銷還是?CPU?使用效率都比?Perlbal?要好很多。作為郵件代理服務器:?
Nginx?同時也是一個非常優秀的郵件代理服務器(最早開發這個產品的目的之一也是作為郵件代理服務器),?Last.fm?描述了成功并且美妙的使用經驗。Nginx?是一個安裝非常簡單,配置文件非常簡潔(還能夠支持perl語法),?Bugs非常少的服務器:?Nginx?啟動特別容易,并且幾乎可以做到?7*24?不間斷運行,即使運行數個月也不需要重新啟動。?你還能夠不間斷服務的情況下進行軟件版本的升級。
?
Nginx的安裝
模塊依賴性Nginx需要依賴下面3個包
1.?gzip?模塊需要?zlib?庫?(?下載:?http://www.zlib.net/?)
2.?rewrite?模塊需要?pcre?庫?(?下載:?http://www.pcre.org/?)
3.?ssl?功能需要?openssl?庫?(?下載:?http://www.openssl.org/?)
?
Nginx包下載:?http://nginx.org/en/download.html
?
依賴包安裝順序依次為:openssl、zlib、pcre,?然后安裝Nginx包.
?
圖解教程
第一步:?下載安裝所需包
openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.2.6.tar.gz
第二步:依次安裝openssl-fips-2.0.2.tar.gz,?zlib-1.2.7.tar.gz,?pcre-8.21.tar.gz,?nginx-1.2.6.tar.gz
1.安裝openssl-fips-2.0.2.tar.gz
[root@localhost mrms]# tar -zxvf openssl-fips-2.0.2.tar.gz [root@localhost mrms]# cd openssl-fips-2.0.2[root@localhost openssl-fips-2.0.2]# ./config [root@localhost openssl-fips-2.0.2]# make[root@localhost openssl-fips-2.0.2]# make install
2.安裝zlib-1.2.7.tar.gz
[root@localhost mrms]# tar -zxvf zlib-1.2.7.tar.gz[root@localhost mrms]# cd zlib-1.2.7[root@localhost zlib-1.2.7]# ./configure [root@localhost zlib-1.2.7]# make[root@localhost zlib-1.2.7]# make install
3.安裝pcre-8.21.tar.gz
[root@localhost mrms]# tar -zxvf pcre-8.21.tar.gz[root@localhost mrms]# cd pcre-8.21[root@localhost pcre-8.21]# ./configure [root@localhost pcre-8.21]# make[root@localhost pcre-8.21]# make install
?4.安裝?nginx-1.2.6.tar.gz
[root@localhost mrms]# tar -zxvf nginx-1.2.6.tar.gz [root@localhost mrms]# cd nginx-1.2.6[root@localhost nginx-1.2.6]# ./configure --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2[root@localhost nginx-1.2.6]# make[root@localhost nginx-1.2.6]# make install
至此Nginx的安裝完成!
?
第三步:檢測是否安裝成功
[root@localhost nginx-1.2.6]# cd /usr/local/nginx/sbin[root@localhost sbin]# ./nginx -t
出現如下所示提示,表示安裝成功
?
啟動nginx
[root@localhost sbin]# ./nginx
查看端口
[root@localhost sbin]# netstat -ntlp
結果如下
?
配置Nginx的負載均衡與分發策略
upstream localhost {
? ? server 192.168.1.125;
? ? server 192.168.1.135;
}
centos7部署vue項目, location / {
? ? proxy_pass http://localhost;
? ? index index.html index.htm;
? ? proxy_set_header Host $host;
}
?
轉載請注明出處[http://www.cnblogs.com/dennisit/archive/2012/12/26/2834719.html]
?