溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法

發(fā)布時(shí)間:2022-04-29 15:41:44 來(lái)源:億速云 閱讀:687 作者:iii 欄目:大數(shù)據(jù)

這篇“Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法”文章吧。

首先去官網(wǎng)下載軟件包,解壓,路徑最好不要有中文

nginx配置的路徑問(wèn)題

由于在windows下文件路徑可以用”\”, 也可以用”\\”, 也可以用”/”作為路徑做分隔符。但”\”最容易引發(fā)問(wèn)題,所以要盡量避免使用。

不要添加path,否則會(huì)引發(fā)錯(cuò)誤,config文件路徑找不到

比如我解壓在e盤

cmd命令定位到nginx.exe所在文件夾cd e:\worksoftware\nginx-1.10.1
然后執(zhí)行,首先保證nginx.conf文件配置沒(méi)問(wèn)題

其實(shí)nginx最重要的和最主要的工作就是配置文件,其他沒(méi)什么需要我們應(yīng)用開發(fā)人員關(guān)注的,除非想修改底層源碼.
nginx.conf配置如下:

#user nobody; 
worker_processes 1; 
#工作進(jìn)程的個(gè)數(shù),可以配置多個(gè) 
 
#全局錯(cuò)誤日志及pid文件 
error_log /worksoftware/nginx-1.10.1/logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 
 
pid  /worksoftware/nginx-1.10.1/logs/nginx.pid; 
 
 
events { 
 worker_connections 1024; #單個(gè)進(jìn)程最大連接數(shù)(最大連接數(shù)=連接數(shù)*進(jìn)程數(shù)) 
} 
 
#設(shè)定http服務(wù)器,利用它的反向代理功能提供負(fù)載均衡支持 
http { 
 include  mime.types; #設(shè)定配置文件位置,這里的conf是指nginx.conf所在的目錄,也可以用絕對(duì)路徑指定其他地方的配置文件 
 default_type application/octet-stream; #默認(rèn)類型-8進(jìn)制文件流 
 
 #設(shè)定日志格式 
 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
 #     '$status $body_bytes_sent "$http_referer" ' 
 #     '"$http_user_agent" "$http_x_forwarded_for"'; 
  
 #設(shè)定訪問(wèn)日志 
 #access_log /worksoftware/nginx-1.10.1/logs/access.log main; 
 
 sendfile  on; #是否激活sendfile()函數(shù),比默認(rèn)模式更有效率 
 #tcp_nopush  on; #將http響應(yīng)頭壓縮到一個(gè)包中發(fā)送,僅在sendfile開啟時(shí)才能配合使用 
 
 #連接超時(shí)時(shí)間 
 #keepalive_timeout 0; 
 keepalive_timeout 65; 
 
 gzip on; #啟用gzip壓縮 
 
 #服務(wù)器的集群 
 #設(shè)定負(fù)載均衡的服務(wù)器列表 支持多組的負(fù)載均衡,可以配置多個(gè)upstream 來(lái)服務(wù)于不同的server. 
 #nginx 的 upstream 支持 幾 種方式的分配 
 #1)、輪詢(默認(rèn)) 每個(gè)請(qǐng)求按時(shí)間順序逐一分配到不同的后端服務(wù)器,如果后端服務(wù)器down掉,能自動(dòng)剔除。 
 #2)、weight 指定輪詢幾率,weight和訪問(wèn)比率成正比,用于后端服務(wù)器性能不均的情況。 跟上面樣,指定了權(quán)重。 
 #3)、ip_hash 每個(gè)請(qǐng)求按訪問(wèn)ip的hash結(jié)果分配,這樣每個(gè)訪客固定訪問(wèn)一個(gè)后端服務(wù)器,可以解決session的問(wèn)題。 
 #4)、fair   
 #5)、url_hash #urlhash 
  
 #upstream imicrosoft.net 
 #{ 
  #服務(wù)器集群名字 
  #服務(wù)器配置 weight是權(quán)重的意思,權(quán)重越大,分配的概率越大。 
  #server 192.98.12.60:1985 weight=3 max_fails=2 fail_timeout=30s; 
  #server 192.98.12.42:8086 weight=3 max_fails=2 fail_timeout=30s; 
   
  #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大 
  #1.down 表示單前的server暫時(shí)不參與負(fù)載 
  #2.weight 默認(rèn)為1.weight越大,負(fù)載的權(quán)重就越大。  
  #3.backup: 其它所有的非backup機(jī)器down或者忙的時(shí)候,請(qǐng)求backup機(jī)器。所以這臺(tái)機(jī)器壓力會(huì)最輕。   
  #本例是指在同一臺(tái)服務(wù)器,多臺(tái)服務(wù)器改變ip即可  
 # server 127.0.0.1:8055 weight=4 down; 
 # server 127.0.0.1:8010 weight=5 backup; 
 #} 
  
  
 upstream localhost 
 {  
  server 127.0.0.1:9000 weight=3 max_fails=2 fail_timeout=200s; 
  server 127.0.0.1:8086 weight=5 max_fails=2 fail_timeout=200s; 
 } 
  
  
 #當(dāng)前的nginx的配置,代理服務(wù)器的地址,即nginx安裝的服務(wù)器地址、監(jiān)聽端口、默認(rèn)地址, 
 #設(shè)定虛擬主機(jī),默認(rèn)為監(jiān)聽80端口 
 server 
 { 
  listen  9090; #偵聽9090端口 
  #對(duì)于server_name,如果需要將多個(gè)域名的請(qǐng)求進(jìn)行反向代理,可以配置多個(gè)server_name來(lái)滿足要求 
  server_name localhost; #當(dāng)前服務(wù)的域名 
   
  charset utf8; 
  #charset koi8-r; 
  
  #設(shè)定本虛擬主機(jī)的訪問(wèn)日志 
  #access_log logs/host.access.log main; 
 
   
  #如果訪問(wèn) /images/*, /js/*, /css/* 資源,則直接取本地文件,不用轉(zhuǎn)發(fā)。 
  #但如果文件較多效果不是太好。 
  #location ~ .*\.(jpg|jpeg|gif|css|png|ico|html)$ 
  #{ 
  # expires 30d; 
  # root /nginx-1.10.1;#root: 
  # break; 
  #} 
   
  #對(duì) "/" 啟用負(fù)載均衡 
  location / { 
    
   root html;  #默認(rèn)主頁(yè)目錄在nginx安裝目錄的html子目錄 
   
   index index.html index.htm index.aspx; #沒(méi)有索引頁(yè)時(shí),羅列文件和子目錄 
   #proxy_pass http://www.imicrosoft.net; #跟載均衡服務(wù)器的upstream對(duì)應(yīng)     
   autoindex on; #沒(méi)有索引頁(yè)時(shí),羅列文件和子目錄 
   
   #保留用戶真實(shí)信息 
   proxy_redirect off; #url不跳轉(zhuǎn) 
   proxy_set_header host $host; 
   proxy_set_header x-real-ip $remote_addr; 
   proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
   #緩沖區(qū)代理緩沖用戶端請(qǐng)求的最大字節(jié)數(shù),可以理解為先保存到本地再傳給用戶 
   # client_body_buffer_size 128k; 
   # #跟后端服務(wù)器連接超時(shí)時(shí)間 發(fā)起握手等候響應(yīng)超時(shí)時(shí)間 
   # proxy_connect_timeout 12; 
   # #連接成功后 等待后端服務(wù)器響應(yīng)時(shí)間 其實(shí)已進(jìn)入后端的排隊(duì)之中等候處理 
   # proxy_read_timeout 90; 
   # #代理請(qǐng)求緩存區(qū) 這個(gè)緩存區(qū)間會(huì)保存用戶的頭信息一共nginx進(jìn)行規(guī)則處理 一般只要能保存下頭信息即可 
   # proxy_send_timeout 90; 
   # #同上 告訴nginx保存單個(gè)用的幾個(gè)buffer最大用多大空間 
   # proxy_buffer_size 4k; 
   # proxy_buffers 4 32k; 
   # #如果系統(tǒng)很忙的時(shí)候可以申請(qǐng)國(guó)內(nèi)各大的proxy_buffers 官方推薦 *2 
   # proxy_busy_buffers_size 64k; 
   # #proxy 緩存臨時(shí)文件的大小 
   proxy_temp_file_write_size 64k; 
   # proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
   proxy_max_temp_file_size 128m; 
   #啟動(dòng)代理 
   proxy_pass http://localhost; 
   client_max_body_size 10m; #允許客戶端請(qǐng)求的最大單個(gè)文件字節(jié)數(shù) 
  } 
 
   
   
  #示例一 
  #location / { 
  #  proxy_pass http://imicrosoft.net; 
  #  
  #  proxy_redirect default; 
  #   
  #  proxy_set_header host $host; 
  #  proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
  #示例二 
  #location /tileservice { 
  #  proxy_pass http://cluster/mongotileservice/tileservice; 
  #  proxy_set_header host $host; 
  #  proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
   
  #error_page 404    /404.html; 
 
  # redirect server error pages to the static page /50x.html 
  # 
  error_page 500 502 503 504 /50x.html; 
  location = /50x.html { 
   root html; 
  } 
 
  # proxy the php scripts to apache listening on 127.0.0.1:80 
  #對(duì) "/xxxxx.php" 啟用負(fù)載均衡 
  #location ~ \.php$ { 
  # proxy_pass http://127.0.0.1; 
  #} 
   
  #location /baidu 
  #{ 
  #proxy_pass http://www.google.com; 
  #proxy_set_header host $host; 
  #proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; 
  #} 
   
  # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 
  # 
  #location ~ \.php$ { 
  # root   html; 
  # fastcgi_pass 127.0.0.1:9000; 
  # fastcgi_index index.php; 
  # fastcgi_param script_filename /scripts$fastcgi_script_name; 
  # include  fastcgi_params; 
  #} 
 
  # deny access to .htaccess files, if apache's document root 
  # concurs with nginx's one 
  # 
  #location ~ /\.ht { 
  # deny all; 
  #} 
 } 
 
 
 # another virtual host using mix of ip-, name-, and port-based configuration 
 # 
 #server { 
 # listen  8000; 
 # listen  somename:8080; 
 # server_name somename alias another.alias; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
 
 # https server 
 # 
 #server { 
 # listen  443 ssl; 
 # server_name localhost; 
 
 # ssl_certificate  cert.pem; 
 # ssl_certificate_key cert.key; 
 
 # ssl_session_cache shared:ssl:1m; 
 # ssl_session_timeout 5m; 
 
 # ssl_ciphers high:!anull:!md5; 
 # ssl_prefer_server_ciphers on; 
 
 # location / { 
 #  root html; 
 #  index index.html index.htm; 
 # } 
 #} 
 
}

結(jié)果如圖:

Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法

Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法

Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法

iis站點(diǎn)

Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法

以上就是關(guān)于“Windows安裝nginx1.10.1反向代理訪問(wèn)IIS網(wǎng)站的方法”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI