瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          nginx和tomcat負載簡單配置(windows環境)

          Posted on 2011-12-07 10:40 瘋狂 閱讀(6973) 評論(2)  編輯  收藏 所屬分類: java性能架構nginx

          本文講了windows環境下的nginxtomcat的一個簡單的配置實例包括dwr的的js特殊的地方配置。當然nginx只有才unix下才能表現出好的性能,主要是io模型等方面。
          關于linux下的配置可見于網上的這篇文章http://bbs.linuxtone.org/forum.php?mod=viewthread&tid=394
           項目demo的下載:/Files/freeman1984/ndemo.rar,里面包含了簡單的測試項目和配置文件,以及nginx的參考文檔一份。

          項目單獨在tomcat下訪問路徑為: http://localhost:8088/ndemo/server.jsp

          Nginx下訪問路徑:http://www.joe.com/server.jsp  其中(www.joe.com是我在hosts文件里面配置的

          一下是nginx的配置:


          Nginx.conf
          內容:

           

          #user nobody;

          worker_processes 
          2#進程數,和cpu個數相關

          pid        logs
          /nginx.pid;

          events {

              worker_connections 
          1024;#每個進程的支持的連接數

          }

           

          http {

              include       mime
          .types;

              default_type application
          /octet-stream;

              
          #日志部分

              log_format main  
          '$remote_addr - $remote_user [$time_local] "$request" '

                                
          '$status $body_bytes_sent "$http_referer" '

                                
          '"$http_user_agent" "$http_x_forwarded_for"';

              sendfile        on;

              

              keepalive_timeout 
          65;

           

              include gzip
          .conf;#啟動數據壓縮

           

               

              server {

                  
          listen       80;

                  server_name www
          .joe.com;#此部分測試的時候可以在host文件里面加上

                  root   E
          :\apache-tomcat-6.0.32\webapps;#項目路徑,直接和后臺使用一個目錄

                  error_page 
          404 /ndemo/404.html;

                  error_page   
          500 502 503 504 /ndemo/50x.html;

                 

                  location 
          ~ ^/(WEB-INF)/ {

                      deny all;

                  }

                  
          #此部分主要是dwr的js有寫是服務器動態生成的,不能交給nginx處理,這樣會出現404,需要單獨處理并交給服務器處理。

                   location 
          /ndemo/dwr/ {    

                       proxy_pass http
          ://localhost:8088/ndemo/dwr/;

                       include proxy
          .conf;

                  }

          #其他的靜態文件處理dwr的都交給nginx處理

                  location 
          ~ \.


          (htm
          |html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf)$ {

                      access_log off;

                      expires 24h;

                  }

                 
          #注意我的上下文是ndemo

                 location 
          /ndemo/ {

                       proxy_pass http
          ://localhost:8088/ndemo/;

                       include proxy
          .conf;

                  }

                  
          #訪問根目錄下的路徑也就是webapp,默認跳轉到ndemo項目的路徑下,也就是跳轉到上面的路徑

                  location 
          / {

                       rewrite (
          .*)$ /ndemo$1 permanent;

                  }

                 location 
          ~ ^/NginxStatus {#nginx的狀態監控需要basic密碼保護,可使用apache的工具生成,方式可見于http://www.aygfsteel.com/freeman1984/articles/363943.html}

                      stub_status on;

                      access_log off;

                      auth_basic              
          "valid-user";

                      auth_basic_user_file ewds_pw;

                 }

              }

           

          }

           

          proxy.conf

           

          proxy_redirect          off;

          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_max_body_size    10m;

          client_body_buffer_size 128k;

          proxy_connect_timeout   
          300;

          proxy_send_timeout      
          300;

          proxy_read_timeout      
          300;

          proxy_buffer_size       4k;

          proxy_buffers           
          4 32k;

          proxy_busy_buffers_size 64k;

          proxy_temp_file_write_size 64k;

           

          gzip.conf

           

          gzip            on;

          gzip_min_length     
          1024;

          gzip_types      text
          /plain text/css application/x-javascript; 

           

          順便展示單獨使用tomcat和使用了nginxgzip的請求對照情況,可以明顯發現nginx對靜態文件的處理效率非常高。

           

          單獨使用tomcat

           

          使用nginxgzip壓縮后的請求情況

           


          評論

          # re: nginx和tomcat負載簡單配置(windows環境)  回復  更多評論   

          2011-12-10 13:05 by tb
          不錯 好資料

          # re: nginx和tomcat負載簡單配置(windows環境)[未登錄]  回復  更多評論   

          2015-07-29 00:39 by alex
          你下面的訪問速度快是因為有瀏覽器緩存
          主站蜘蛛池模板: 句容市| 车险| 建德市| 浙江省| 高阳县| 高州市| 万全县| 华亭县| 黔西县| 凤庆县| 井冈山市| 德令哈市| 万全县| 靖江市| 翁牛特旗| 平潭县| 鱼台县| 靖远县| 班戈县| 罗江县| 平昌县| 柘城县| 平邑县| 司法| 新安县| 顺昌县| 桃园市| 灵山县| 牙克石市| 景泰县| 安泽县| 澄迈县| 化隆| 长丰县| 钦州市| 镇坪县| 康保县| 太仆寺旗| 虹口区| 和林格尔县| 花莲县|