posts - 495,comments - 227,trackbacks - 0
          原文http://xjtom78.iteye.com/blog/1107861

          Ubuntu10.10環(huán)境:Nginx+Tomcat6


          我們下面簡(jiǎn)單說(shuō)下ubuntu10.10下如何安裝配置,主要以圖片為主,簡(jiǎn)單解釋。

           

          1、下載Nginx

                地址:http://nginx.org/en/download.html,linux版本:nginx-0.8.20.tar.。解壓縮命令:


          tar -zxvf nginx-0.8.20.tar.gz


          2、編譯安裝Nginx


               Nginx依賴一些其他PCRE、openssl(依賴libssl-dev),本人筆記本Ubuntu環(huán)境已經(jīng)安裝PCRE,僅需安裝依賴的openssl,下面我們簡(jiǎn)單說(shuō)下如何安裝PCRE和openssl等


               PCRE下載地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/


           

          Shell代碼 
          1. tar zxvf  pcre-8.01.tar.gz  
          2. cd pcre-8.01  
          3. sudo ./configure  
          4. sodu make  
          5. sodu make install  

            

              openssl通過(guò)apt-get install安裝,命令、截圖如下:

          Shell代碼 
          1. sudo apt-get install openssl  
          2. sudo apt-get install libssl-dev  
          3. //如缺少其他包,請(qǐng)采用此方法安裝,ubuntu有依賴提示  

           

           
           依賴的軟件包安裝完畢,下面來(lái)編譯Nginx:

          Shell代碼 
          1. #將window共享目錄軟件拷貝到當(dāng)前工作目錄  
          2. cp /mnt/fileshare/nginx-0.8.20.tar.gz ./  
          3.   
          4. #解壓縮軟件包  
          5. tar zxvf nginx-0.8.20.tar.gz  
          6.   
          7.  cd nginx-0.8.20  
          8. //編譯源碼,默認(rèn)使用nobody,指定本機(jī)已存在的用戶,組,啟用nginx-status功能,監(jiān)控nginx狀態(tài)。啟動(dòng)debug  
          9.  sudo ./configure  --user=niumd --group=niumd --with-debug --with-http_stub_status_module   
          10.    
          11.   
          12. sudo make   
          13. sudo make install  

           
             截圖 如下:

           

          安裝結(jié)果截圖如下:

           

           

          編譯安裝正確結(jié)束,按照上述window下方法檢查默認(rèn)配置,然后在默認(rèn)配置下啟動(dòng)nginx,訪問(wèn)http://127.0.0.1,如下圖說(shuō)明成功

           

           

          Nginx配置成功后我們對(duì)window下nginx.conf少做修改,如下:

          Ubuntu nginx.conf代碼 
          1. #Nginx所用用戶和組  
          2. user  niumd niumd;  
          3.   
          4. #工作的子進(jìn)程數(shù)量(通常等于CPU數(shù)量或者2倍于CPU)  
          5. worker_processes  2;  
          6.   
          7. #錯(cuò)誤日志存放路徑  
          8. #error_log  logs/error.log;  
          9. #error_log  logs/error.log  notice;  
          10. error_log  logs/error.log  info;  
          11.   
          12. #指定pid存放文件  
          13. pid        logs/nginx.pid;  
          14.   
          15. events {  
          16.   #使用網(wǎng)絡(luò)IO模型linux建議epoll,F(xiàn)reeBSD建議采用kqueue  
          17.     use epoll;  
          18.       
          19.     #允許最大連接數(shù)  
          20.     worker_connections  2048;  
          21. }  
          22.   
          23. http {  
          24.     include       mime.types;  
          25.     default_type  application/octet-stream;  
          26.   
          27.   #定義日志格式  
          28.     #log_format  main  '$remote_addr - $remote_user [$time_local] $request '  
          29.     #                  '"$status" $body_bytes_sent "$http_referer" '  
          30.     #                  '"$http_user_agent" "$http_x_forwarded_for"';  
          31.   
          32.     #access_log  off;  
          33.     access_log  logs/access.log;  
          34.   
          35.     client_header_timeout  3m;  
          36.     client_body_timeout    3m;  
          37.     send_timeout           3m;  
          38.    
          39.     client_header_buffer_size    1k;  
          40.     large_client_header_buffers  4 4k;  
          41.   
          42.     sendfile        on;  
          43.     tcp_nopush      on;  
          44.     tcp_nodelay     on;  
          45.   
          46.     #keepalive_timeout  75 20;  
          47.   
          48.     include    gzip.conf;  
          49.     upstream localhost {  
          50.      #ip_hash  
          51.       #ip_hash;  
          52.       server localhost:18081;  
          53.       server localhost:18080;  
          54.      }  
          55.   
          56.     server {  
          57.             listen       80;  
          58.             server_name  localhost;     
          59.   
          60.             location / {  
          61.               proxy_connect_timeout   3;  
          62.               proxy_send_timeout      30;  
          63.               proxy_read_timeout      30;  
          64.                 proxy_pass http://localhost;  
          65.             }  
          66.               
          67.    }  
          68. }  

            對(duì)于上面關(guān)于ubuntu下Nginx配置和window下基本相同,區(qū)別在使用的IO網(wǎng)絡(luò)模型,linux下建議使用epoll,另外就是運(yùn)行所用的用戶和組;

            

          3、配置tomcat

              請(qǐng)參考window下配置,完全相同。

          4、啟動(dòng)停止nginx

              ubuntu下啟動(dòng)nginx與window稍有不同,大致啟動(dòng)停止方法如下。

           

          Java代碼 
          1. #nginx目錄執(zhí)行  
          2. sbin/nginx  
          3. 或通過(guò)-c 指定配置文件  
          4. sbin/nginx -c usr/local/nginx8.20/conf/nginx/conf  

           

              

          Shell代碼 
          1. niumd@niumd-laptop:/usr/local/nginx$ pwd  
          2. /usr/local/nginx  
          3. niumd@niumd-laptop:/usr/local/nginx$ sudo sbin/nginx -t  
          4. the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok  
          5. configuration file /usr/local/nginx/conf/nginx.conf test is successful  
          6. niumd@niumd-laptop:/usr/local/nginx$ sudo sbin/nginx -v  
          7. nginx version: nginx/0.8.20  
          8. niumd@niumd-laptop:/usr/local/nginx$ sudo sbin/nginx -V  
          9. nginx version: nginx/0.8.20  
          10. built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)   
          11. configure arguments: --user=niumd --group=niumd --with-debug --with-http_sub_module  
          12. niumd@niumd-laptop:/usr/local/nginx$ sudo sbin/nginx   
          13. niumd@niumd-laptop:/usr/local/nginx$ ps -ef|grep nginx  
          14. root      5158     1  0 22:32 ?        00:00:00 nginx: master process sbin/nginx  
          15. niumd     5159  5158  0 22:32 ?        00:00:00 nginx: worker process  
          16. niumd     5161  1577  0 22:32 pts/0    00:00:00 grep --color=auto nginx  
          17. niumd@niumd-laptop:/usr/local/nginx$   

           

               我們通過(guò)ps  -ef|grep nginx,看到如下結(jié)果:

             

           

          注意:在啟動(dòng)時(shí)linux提示一句警告【warn】……,是因?yàn)槲覀冊(cè)O(shè)置的 #允許最大連接數(shù) worker_connections  2048,超過(guò)linux默認(rèn)1024的限制。

                 停止:kill -信號(hào)類型 pid

                 nginx/logs目錄下有個(gè)nginx。pid的文件,此文件記錄了每次運(yùn)行的pid,也可以通過(guò)ps命令查詢。

          信號(hào)類型如下:

                 

           

          信號(hào)類型 描述
          RERM.INT 快速關(guān)閉
          HUP 平滑重啟,加載配置
          USR1         
           重新加載日志
                  
           重新加載日志
                  
           重新加載日志
          重新加載日志
          USER2 平滑升級(jí)執(zhí)行程序
          WINCH 從容關(guān)閉工作進(jìn)程
          QUIT 從容關(guān)閉

           

          參考資料:

          http://www.oschina.net/bbs/thread/9301

          oschina.net 生產(chǎn)配置,此網(wǎng)站采用java語(yǔ)言,nginx,tomcat服務(wù)器。

          http://nginx.org/

          張宴:<<實(shí)戰(zhàn)Nginx>>

          轉(zhuǎn)載:http://tmsoft.lsxy.com/index.php?load=read&id=938



          附加信息:

          三.實(shí)現(xiàn)步驟:
          1.下載安裝JDK,Nginx,tomcat;
          2.修改tomcat的相關(guān)端口,方法為:sudo vi /opt/tomcat6(.1)/conf/server.xml,分別找到相關(guān)端口,修改即可;
          3.sudo vi /etc/nginx/conf.d/proxy.conf,內(nèi)容為:
          #!nginx (-) 
          # proxy.conf 
          proxy_redirect          off;
          proxy_set_header        Host $host;
          proxy_set_header        X-Real-IP $remote_addr;  #獲取真實(shí)ip
          #proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; #獲取代理
          者的真實(shí)ip
          client_max_body_size    10m;
          client_body_buffer_size 128k;
          proxy_connect_timeout   90;
          proxy_send_timeout      90;
          proxy_read_timeout      90;
          proxy_buffer_size       4k;
          proxy_buffers           4 32k;
          proxy_busy_buffers_size 64k;
          proxy_temp_file_write_size 64k;
          4.sudo vi /etc/nginx/site-available/default,修改內(nèi)容如下:

          upstream  localhost.com {              
             server   127.0.0.1:8888;   
             server   127.0.0.1:8889;
          }


          server {
             #listen   80; ## listen for ipv4; this line is default and implied
             #listen   [::]:80 default ipv6only=on; ## listen for ipv6


             root /usr/share/nginx/www;
             index index.html index.htm index.jsp index.do;


             # Make site accessible from http://localhost/
             server_name localhost;


             location ~ .*.(jsp|do|action)?$ { #所有jsp的頁(yè)面均交由tomcat處理
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_pass http://localhost.com; #轉(zhuǎn)向tomcat處理
             }
             location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { #設(shè)定訪問(wèn)靜態(tài)文件直接讀取不經(jīng)過(guò)tomcat
            expires      30d;
             }
             location ~ .*.(js|css)?$ {
              expires      1h;
             }
          }

          posted on 2011-10-21 09:59 SIMONE 閱讀(1115) 評(píng)論(0)  編輯  收藏 所屬分類: LINUX
          主站蜘蛛池模板: 崇州市| 于都县| 米脂县| 厦门市| 七台河市| 屏东县| 华安县| 贵溪市| 大姚县| 乌鲁木齐县| 垫江县| 巴塘县| 新安县| 资溪县| 婺源县| 拜泉县| 玉龙| 娱乐| 名山县| 德保县| 临汾市| 喀什市| 凤庆县| 胶州市| 琼结县| 芜湖市| 资阳市| 广灵县| 贵定县| 富锦市| 靖西县| 岐山县| 临朐县| 眉山市| 南郑县| 共和县| 丹凤县| 二手房| 略阳县| 马龙县| 资源县|