CentOS Nginx服務(wù)器配置nginx.conf
在向大家詳細(xì)介紹CentOS Nginx之前,首先讓大家了解下CentOS Nginx,然后全面介紹CentOS Nginx,希望對(duì)大家有用。CentOS Nginx 已經(jīng)是目前公認(rèn)的效率很高的代理服務(wù),同時(shí)可以用來(lái)做負(fù)載均衡。
由于項(xiàng)目目前只有一臺(tái)CentOS Nginx 的服務(wù)器,無(wú)法用來(lái)測(cè)試,所以打算找下Nginx windows下版本;http://www.kevinworthington.com/nginx/win32/以上為win32的版本用戶訪問(wèn) sp.imichat.com 均衡到 10.10.10.181:8080; 10.10.10.181:8081; 10.10.10.181:8082; 這3臺(tái)服務(wù)器CentOS Nginx
配置CentOS Nginx 的nginx.conf
- http {}增加如下內(nèi)容
- upstream sp.imichat.com
- {server 10.10.10.181:8080;
- server 10.10.10.181:8081;
- server 10.10.10.181:8082; }
- server {} 修改異俠信息:
- listen 80;
- server_name sp.imichat.com;
- #charset koi8-r;
- #access_log logs/host_access_log main;
- location / {
- proxy_pass http://sp.imichat.com;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- access_log logs/sp.imichat.com.log combined;
- [/code]
啟動(dòng)181上的3個(gè)tomcat,修改tomcat首頁(yè)加入端口信息,以用來(lái)清晰看到當(dāng)前分配到那臺(tái)tomcat啟動(dòng)Nginx,訪問(wèn) http://sp.imichat.com/可看到請(qǐng)求被發(fā)送到3臺(tái)服務(wù)器。
抓http包可看到request為
- GET / HTTP/1.1
- Host: sp.imichat.com
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: en-us,zh-cn;q=0.5
- Accept-Encoding: gzip,deflate
- Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7
- Keep-Alive: 300
- Connection: keep-alive
- Cookie: JSESSIONID=A75E09D2EBF769A7BD95195E29DE87DE; key=1227008000183; memberName=admin; memberType=%7C%u8D85%u7EA7%u7BA1%u7406%u5458%7C
- Pragma: no-cache
- Cache-Control: no-cache
response:
- HTTP/1.1 200 OK
- Server: nginx/0.7.21-win32
- Date: Tue, 18 Nov 2008 12:12:33 GMT
- Content-Type: text/html
- Connection: keep-alive
- ETag: W/"8157-1227009260637"
- Last-Modified: Tue, 18 Nov 2008 11:54:20 GMT
- Content-Length: 8157
【編輯推薦】