一:簡介
Tomcat在高並發環境下處理動態請求時效能很低,而在處理靜態頁面則更加脆弱。雖然Tomcat的最新版本支援epoll,但透過Nginx來處理靜態頁面要比透過Tomcat處理在效能方面好很多。
二:下載安裝(以windows環境為例)
1、下載位址
下載位址:點這裡
2、目錄結構
<code> Nginx- |_ conf 配置目录 |_ contrib |_ docs 文档目录 |_ logs 日志目录 |_ temp 临时文件目录 |_ html 静态页面目录 |_ nginx.exe 主程序 </code>
三:啟動和停止nginx服務
cmd進入nginx解壓縮目錄
執行start nginx,就可以啟動服務(或nginx或nginx.exe)
建議使用第一種,
其他二種會使你的cmd視窗一直處於執行中,不能進行其他命令操作
<code><span>#Nginx所用用户和组</span><span>#user niumd niumd;</span><span>#工作的子进程数量(通常等于CPU数量或者2倍于CPU)</span> worker_processes <span>2</span>; <span>#错误日志存放路径</span><span>#error_log logs/error.log;</span><span>#error_log logs/error.log notice;</span> error_log logs/error.log info; <span>#指定pid存放文件</span> pid logs/nginx.pid; events { <span>#使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue</span><span>#use epoll;</span><span>#允许最大连接数</span> worker_connections <span>2048</span>; } http { <span>include</span> mime.types; default_type application/octet-stream; <span>#定义日志格式</span><span>#log_format main '$remote_addr - $remote_user [$time_local] $request '</span><span># '"$status" $body_bytes_sent "$http_referer" '</span><span># '"$http_user_agent" "$http_x_forwarded_for"';</span><span>#access_log off;</span> access_log logs/access.log; client_header_timeout <span>3</span>m; client_body_timeout <span>3</span>m; send_timeout <span>3</span>m; client_header_buffer_size <span>1</span>k; large_client_header_buffers <span>4</span><span>4</span>k; sendfile <span>on</span>; tcp_nopush <span>on</span>; tcp_nodelay <span>on</span>; <span>#keepalive_timeout 75 20;</span><span>include</span> gzip.conf; upstream localhost { server localhost:<span>8080</span> weight=<span>5</span>; server localhost:<span>9091</span> weight=<span>1</span>; } server { listen <span>80</span>; server_name localhost; location / { proxy_connect_timeout <span>3</span>; proxy_send_timeout <span>30</span>; proxy_read_timeout <span>30</span>; proxy_pass http://localhost; } } } </code>五:負載平衡權重設定
<code> upstream localhost { <span>server</span> localhost:<span>8080</span> weight=<span>5</span>; <span>server</span> localhost:<span>9091</span> weight=<span>1</span>; }</code>').addClass('preh-numbering'). ; $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); 以上就介紹了nginx負載平衡配置,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。