Debian/Ubuntu下Nginx的安裝、反向 Proxy和負載平衡的基本配置

來源:互聯網
上載者:User

Debian/Ubuntu下Nginx的安裝、反向 Proxy和負載平衡的基本配置
源碼安裝

去Nginx官網下載最新穩定版,這裡用的是nginx-1.6.3版。
下載完成後解壓縮,進入該目錄執行:

./configure

如果你的機器上沒有安裝PCER庫、zlib庫等,這一步會出錯。

sudo apt-get install libpcre3-dev zlibc zlib-bin

然後執行:

sudo makesudo make install

完成後,nginx會預設安裝在/usr/local/nginx目錄下。

反向 Proxy的基本配置

nginx預設使用的設定檔在/user/local/nginx/conf/nginx.conf中。假設上遊伺服器是JBoss叢集,那麼可以在http塊中進行如下配置:

upstream jboss {    server localhost:8080;    server xx.xx.xx.xx:port    server server-domain-name}

server塊中進行如下配置:

location / {    proxy_pass http://jboss;}
ip_hash簡單配置

多數情況下如果用nginx作為負載機,那麼我們都希望對於同一個ip,每次都將其交給同一台上遊伺服器處理。配置如下:

upstream jboss { ip_hash; server localhost:8080; server xx.xx.xx.xx:port; server server-domain-name}

這時如果某台JBoss出現問題不能使用,不能直接從上面的配置中刪除該JBoss地址,而是要:

upstream jboss { ip_hash; server localhost:8080; server xx.xx.xx.xx:port down; server server-domain-name;}

然後執行

/usr/local/nginx -s reload

重新載入設定檔即可。

聯繫我們

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