Windows安裝nginx1.10.1反向 Proxy訪問IIS網站_nginx

來源:互聯網
上載者:User

首先去官網下載軟體包,解壓,路徑最好不要有中文

Nginx配置的路徑問題

由於在Windows下檔案路徑可以用”\”, 也可以用”\\”, 也可以用”/”作為路徑做分隔字元。但”\”最容易引發問題,所以要盡量避免使用。

不要添加PATH,否則會引發錯誤,config檔案路徑找不到

比如我解壓在E盤

cmd命令定位到nginx.exe所在檔案夾cd E:\WorkSoftWare\nginx-1.10.1
然後執行,首先保證nginx.conf檔案配置沒問題

其實nginx最重要的和最主要的工作就是設定檔,其他沒什麼需要我們應用開發人員關注的,除非想修改底層源碼.
nginx.conf配置如下:

#user nobody; worker_processes 1; #背景工作處理序的個數,可以配置多個  #全域錯誤記錄檔及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; #單個進程最大串連數(最大串連數=串連數*進程數) }  #設定http伺服器,利用它的反向 Proxy功能提供負載平衡支援 http {  include  mime.types; #設定設定檔位置,這裡的conf是指nginx.conf所在的目錄,也可以用絕對路徑指定其他地方的設定檔  default_type application/octet-stream; #預設類型-8進位檔案流   #設定日誌格式  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '  #     '$status $body_bytes_sent "$http_referer" '  #     '"$http_user_agent" "$http_x_forwarded_for"';    #設定訪問日誌  #access_log /WorkSoftWare/nginx-1.10.1/logs/access.log main;   sendfile  on; #是否啟用sendfile()函數,比預設模式更有效率  #tcp_nopush  on; #將HTTP回應標頭壓縮到一個包中發送,僅在sendfile開啟時才能配合使用   #連線逾時時間  #keepalive_timeout 0;  keepalive_timeout 65;   gzip on; #啟用Gzip壓縮   #伺服器的叢集  #設定負載平衡的伺服器列表 支援多組的負載平衡,可以配置多個upstream 來服務於不同的Server.  #nginx 的 upstream 支援 幾 種方式的分配  #1)、輪詢(預設) 每個請求按時間順序逐一分配到不同的後端伺服器,如果後端伺服器down掉,能自動剔除。  #2)、weight 指定輪詢幾率,weight和訪問比率成正比,用於後端伺服器效能不均的情況。 跟上面樣,指定了權重。  #3)、ip_hash 每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個後端伺服器,可以解決session的問題。  #4)、fair    #5)、url_hash #Urlhash    #upstream imicrosoft.net  #{   #伺服器叢集名字   #伺服器配置 weight是權重的意思,權重越大,分配的機率越大。   #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參數表示權值,權值越高被分配到的幾率越大   #1.down 表示單前的server暫時不參與負載   #2.weight 預設為1.weight越大,負載的權重就越大。    #3.backup: 其它所有的非backup機器down或者忙的時候,請求backup機器。所以這台機器壓力會最輕。     #本例是指在同一台伺服器,多台伺服器改變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;  }      #當前的Nginx的配置,Proxy 伺服器的地址,即Nginx安裝的伺服器位址、監聽連接埠、預設地址,  #設定虛擬機器主機,預設為監聽80連接埠  server  {   listen  9090; #偵聽9090連接埠   #對於server_name,如果需要將多個網域名稱的請求進行反向 Proxy,可以配置多個server_name來滿足要求   server_name localhost; #當前服務的網域名稱      charset utf8;   #charset koi8-r;     #設定本虛擬機器主機的訪問日誌   #access_log logs/host.access.log main;       #如果訪問 /images/*, /js/*, /css/* 資源,則直接取本地檔案,不用轉寄。   #但如果檔案較多效果不是太好。   #location ~ .*\.(jpg|jpeg|gif|css|png|ico|html)$   #{   # expires 30d;   # root /nginx-1.10.1;#root:   # break;   #}      #對 "/" 啟用負載平衡   location / {        root html;  #預設首頁目錄在nginx安裝目錄的html子目錄       index index.html index.htm index.aspx; #沒有索引頁時,羅列檔案和子目錄    #proxy_pass http://www.imicrosoft.net; #跟載均衡伺服器的upstream對應        autoindex on; #沒有索引頁時,羅列檔案和子目錄       #保留使用者真實資訊    proxy_redirect off; #url不跳轉    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    #緩衝區代理緩衝使用者端請求的最大位元組數,可以理解為先儲存到本地再傳給使用者    # client_body_buffer_size 128k;    # #跟後端伺服器連線逾時時間 發起握手等候響應逾時時間    # proxy_connect_timeout 12;    # #串連成功後 等待後端伺服器回應時間 其實已進入後端的排隊之中等候處理    # proxy_read_timeout 90;    # #代理請求緩衝區 這個緩衝區間會儲存使用者的頭資訊一共Nginx進行規則處理 一般只要能儲存下頭資訊即可    # proxy_send_timeout 90;    # #同上 告訴Nginx儲存單個用的幾個Buffer最大用多大空間    # proxy_buffer_size 4k;    # proxy_buffers 4 32k;    # #如果系統很忙的時候可以申請國內各大的proxy_buffers 官方推薦 *2    # proxy_busy_buffers_size 64k;    # #proxy 緩衝臨時檔案的大小    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;    #啟動代理    proxy_pass http://localhost;    client_max_body_size 10m; #允許用戶端請求的最大單個檔案位元組數   }          #樣本一   #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   #對 "/XXXXX.PHP" 啟用負載平衡   #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;  # }  #}  } 

結果如圖:

IIS網站



以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.