linux nginx 代理iis,nginx 系列 linux下安装以及配置IIS分发
一. 安裝
操作系統(tǒng):centos 7 ,nginx版本1.12.2,windows server 2008 iis
1.1?確認(rèn)nginx所依賴的工具
Zlib: ?nginx提供gzip模塊,需要zlib庫支持,Openssl: nginx提供ssl功能,?Pcre: 支持地址重寫rewrite功能。如果沒有安裝,在root下使用yum來安裝。
-- 檢測是否安裝依賴工具包
[root@xuegod64 hsr]# yum list | grep zlib
[root@xuegod64 hsr]# yum list | grep openssl
[root@xuegod64 hsr]# yum list | grep pcre
1.2 安裝nginx
下載了nginx-1.12.2.tar.gz包后,放在了linux系統(tǒng)目錄/home/hsr/下。
--解壓
[root@xuegod64 hsr]# tar -xzvf nginx-1.12.2.tar.gz
[root@xuegod64 hsr]# cd nginx-1.12.2
--編譯
[root@xuegod64 nginx-1.12.2]# ./configure
--安裝
[root@xuegod64 nginx-1.12.2]# make
[root@xuegod64 nginx-1.12.2]# make install
1.3 生成系統(tǒng)運(yùn)行的nginx用戶
/*
使用-u 來生成用戶ID 8000,
-s 指定用戶登入后所使用的shell,
nginx是指系統(tǒng)用戶
*/
[root@xuegod64 ~]# useradd –u 8000 –s /usr/ sbin/nologin nginx
-- 查看nginx用戶信息
[root@xuegod64 sbin]# cat /etc/passwd
nginx:x:8000:8000::/home/nginx:/sbin/nologin
1.4?啟動nginx
[root@xuegod64 sbin]# pwd
/usr/local/nginx/sbin
[root@xuegod64 sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
上面nginx服務(wù)已經(jīng)啟動成功,后面可以把/usr/local/nginx/sbin目錄添加到path 全局中,就不用在定位到/usr/local/nginx/sbin下。默認(rèn)端口是80(確認(rèn)防火墻已開通80端口)。
--查看nginx進(jìn)程
[root@xuegod64 sbin]# ps -ef | grep nginx
最后查看nginx的運(yùn)行狀態(tài)
[root@xuegod64 sbin]# curl http://192.168.2.101:80
如果沒有出現(xiàn)welcome to nginx,需要查看nginx的日志 (/usr/local/nginx/logs),在要分發(fā)的客戶端(iis服務(wù))拼通? telnet 192.168.2.101 80。 也可以在瀏覽器里輸入地址查看狀態(tài),如下:
二.? 配置IIS分發(fā)
2.1 編輯nginx.conf文件(可以先備份一下)
(1) 首先注釋掉nobdy用戶,添加 nginx用戶用戶組,如下腳本
#user nobody;
user nginx nginx;
worker_processes 1;
(2)?添加分發(fā)策略
在http模塊里找到server 節(jié)點(diǎn),里面的location節(jié)點(diǎn),Location 是網(wǎng)站的根目錄, 在location節(jié)點(diǎn)里,添加分發(fā)策略, 如下圖(注意if與 大括號{之間要有空隔)
location / {
root html;
index index.html index.htm;
if ($request_uri ~* \.html$) {
proxy_pass http://htmlservers;
}
if ($request_uri ~* \.aspx$){
proxy_pass http://aspxservers;
}
proxy_pass http://picservers;
}
注意上面的 uri 跟url一樣,統(tǒng)一資源占位符例如如果進(jìn)來是已.html結(jié)尾, 全部轉(zhuǎn)到 http://htmlservers服務(wù)器上,還有aspxservers服務(wù)器,最后是picservers服務(wù)器。(名字自己啟,相當(dāng)一個服務(wù)器池)。 最后picservers相當(dāng)于else。
(3)?定義負(fù)載設(shè)備的ip(這里是IIS服務(wù)器上的50,51 ip),添加位置在http模塊里的最后一行,后期根據(jù)自己的實(shí)際ip,進(jìn)行更改,保存nginx.conf文件退出
upstream htmlservers{
server 192.168.2.50:80;
server 192.168.2.51:80;
}
upstream aspxservers{
server 192.168.2.50:80;
server 192.168.2.51:80;
}
upstream picservers{
server 192.168.2.50:80;
server 192.168.2.51:80;
}
}
(4)?檢查配置是否正確,在重新加載配置
[root@xuegod64 sbin]# pwd
/usr/local/nginx/sbin
[root@xuegod64 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@xuegod64 sbin]# ./nginx -s reload
總結(jié)
以上是生活随笔為你收集整理的linux nginx 代理iis,nginx 系列 linux下安装以及配置IIS分发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux移植wifi sd8688.b
- 下一篇: weblogic12 linux部署,l