nginx配置轉發詳解


nginx各項參數的詳細配置

本文主要講解nginx.conf中server部分配置及多路轉發問題:

 1  server {  2         listen       9090;  3         server_name  127.0.0.1;  4 
 5         #charset koi8-r;  6 
 7         #access_log  logs/host.access.log  main;
 8 
 9         location / { 10  root html; 11  index index.html index.htm; 12  } 13  #Proxy Settings 14         location /mswcf {
15              rewrite    ^.+mswcf/?(.*)$ /$1 break; 16              proxy_pass http://172.16.58.39:8080/;
17  } 18         location /uswcf {
19              rewrite    ^.+uswcf/?(.*)$ /$1 break; 20              proxy_pass http://172.16.58.38:8080/;
21  } 22         location /cswcfw {
23              rewrite    ^.+cswcfw/?(.*)$ /$1 break; 24              proxy_pass http://172.16.58.37/;
25  } 26         #error_page  404              /404.html;
27 }

將不同的服務器地址由location /mswcf 或location /uswcf 或location /cswcfw進行轉發,可以解決瀏覽器端跨域問題;
在瀏覽器地址欄中的訪問方法為:http://127.0.0.1:9090/  默認定位到index.html;
配置文件nginx.conf更改后,需要重新啟動服務器;右鍵 “啟動任務管理器”-->切換到"進程"-->找到“nginx.exe”-->刪除“nginx.exe”-->進入nginx文件所在盤符雙擊nginx.exe,就可重新啟動服務;

 1 $.ajax({
 2         type: 'post',
 3         url: '/mswcf/Message/SyncMessage/GetList',
 4         data:'{"iMUserID":"'+iMUserID+'","syncDatetime":"'+syncDatetime+'"}',
 5         contentType: "application/json; charset=utf-8",  
 6         dataType: 'json',
 7         beforeSend: function(request) {
 8             request.setRequestHeader("accessToken", accessToken);
 9         },
10         success: function (data){
11             console.log(data);
12         },
13         error:function(msg){
14           console.lot(msg);
15          }
16 })
url: '/mswcf/Message/SyncMessage/GetList',是經過nginx轉發之后的地址;

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM