Windows平台使用Nginx配置NodeJs程式

來源:互聯網
上載者:User

標籤:

簡介

Nginx("engine x") 是一個高效能的 HTTP 和 反向 Proxy 伺服器,也是一個 IMAP/POP3/SMTP 伺服器。 Nginx 是由 Igor Sysoev 為俄羅斯訪問量第二的 Rambler.ru 網站開發的,第一個公開版本0.1.0發佈於2004年10月4日。其將原始碼以類BSD許可證的形式發布,因它的穩定性、豐富的功能集、樣本設定檔和低系統資源的消耗而聞名。

安裝

步驟:官網下載Nginx,解壓到D盤目錄,啟動Nginx服務。

官網:http://nginx.org/en/download.html(注意:下載的時候要選擇windows版的)

解壓到D盤根目錄,然後啟動Nginx,運行CMD執行命令:

d:cd nginxstart nginx

Nginx基礎命令:

nginx -s stop          // 停止nginx
nginx -sreload        // 重新載入設定檔
nginx -squit          // 退出nginx

使用

假設現在NodeJs的Express有兩個網站訪問地址:127.0.0.1:3000  | 127.0.0.1::3001 配置負載平衡與健康檢測的預設模組,方法如下:

找到設定檔(我的Nginx安裝目錄為:D:\nginx):D:\nginx\conf\nginx.conf設定替換為如下代碼:

http {    include       mime.types;    default_type  application/octet-stream;        upstream sample {      server 127.0.0.1:3000 max_fails=1 fail_timeout=40s;      server 127.0.0.1:3001 max_fails=1 fail_timeout=40s;      keepalive 64;     }     server {        listen       80;        server_name  127.0.0.1;        location / {            proxy_http_version 1.1;            proxy_set_header Upgrade $http_upgrade;            proxy_set_header Connection ‘upgrade’;            proxy_set_header Host $host;            proxy_cache_bypass $http_upgrade;            proxy_pass http://sample/;            proxy_connect_timeout 1;            proxy_read_timeout 1;        }    }}

現在訪問地址127.0.0.1,Nginx會輪換把請求分別分發給連接埠3000和連接埠3001。

假如有一個伺服器掛掉,則會一直分配到另一個伺服器上,直到檢測癱瘓的伺服器正常訪問之後,恢複輪換請求分發的任務。

 

 

 

 

 

Windows平台使用Nginx配置NodeJs程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.