国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Linux服務器 > 正文

詳解Linux下Nginx+Tomcat整合的安裝與配置

2024-09-05 23:03:32
字體:
來源:轉載
供稿:網友

一、安裝Tomcat和JDK

1、上傳apache-tomcat-6.0.18.tar.gz和jdk-6u12-linux-i586.bin至/usr/local

2、執行如下命令安裝tomcat:

#cd /usr/local #tar zxvf apache-tomcat-6.0.18.tar.gz

解壓完成后將apache-tomcat-6.0.18重命名為tomcat

3、執行如下命令安裝JDK:

#./jdk-6u12-linux-i586.bin

4、配置環境變量:

編輯/etc下的profile文件,加上如下內容: 

JAVA_HOME="/usr/local/jdk1.6.0_12"CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"PATH=".:$PATH:$JAVA_HOME/bin " CATALINA_HOME="/usr/local/tomcat"export JAVA_HOME CATALINA_HOME

5、啟動tomcat并輸入http://localhost:8080,如果看到貓的頁面即tomcat和jdk安裝成功

6、新建文件目錄/home/www為網站存放目錄,設置server.xml文件,在Host name=”localhost”處將appBase=的指向路徑改為/home/www/web

7、創建index.jsp至/home/www/web/ROOT,內容為:“My web!” 

二、安裝Nginx

1、上傳nginx-0.7.63.tar.gz至/usr/local

2、執行如下命令解壓nginx:

#cd /usr/local #tar zxvf nginx-0.7.63.tar.gz

3、編譯安裝nginx

#cd nginx-0.7.63#./configure --with-http_stub_status_module --with-http_ssl_module #啟動server狀態頁和https模塊

執行完后會提示一個錯誤,說缺少PCRE library 這個是HTTP Rewrite 模塊,也即是url靜態化的包

可上傳pcre-7.9.tar.gz,輸入如下命令安裝:

#tar zxvf pcre-7.9.tar.gz #cd pcre-7.9#./configure #make #make install

安裝pcre成功后,繼續安裝nginx

#cd nginx-0.7.63#./configure #make #make install

4、nginx安裝成功后的安裝目錄為/usr/local/nginx

在conf文件夾中新建proxy.conf,用于配置一些代理參數,內容如下:

#!nginx (-) # proxy.conf proxy_redirect     off; proxy_set_header    Host $host; proxy_set_header    X-Real-IP $remote_addr; #獲取真實ip #proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for; #獲取代理者的真實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;

 編輯安裝目錄下conf文件夾中的nginx.conf,輸入如下內容 

#運行nginx所在的用戶名和用戶組 #user www www;  #啟動進程數 worker_processes 8; #全局錯誤日志及PID文件 error_log /usr/local/nginx/logs/nginx_error.log crit;  pid    /usr/local/nginx/nginx.pid;  #Specifies the value for maximum file descriptors that can be opened by this process.  worker_rlimit_nofile 65535; #工作模式及連接數上限 events {  use epoll;  worker_connections 65535; } #設定http服務器,利用它的反向代理功能提供負載均衡支持 http {  #設定mime類型  include    mime.types;  default_type application/octet-stream;  include /usr/local/nginx/conf/proxy.conf;  #charset gb2312;  #設定請求緩沖    server_names_hash_bucket_size 128;  client_header_buffer_size 32k;  large_client_header_buffers 4 32k;  client_max_body_size 8m;      sendfile on;  tcp_nopush   on;   keepalive_timeout 60;   tcp_nodelay on;  # fastcgi_connect_timeout 300; # fastcgi_send_timeout 300; # fastcgi_read_timeout 300; # fastcgi_buffer_size 64k; # fastcgi_buffers 4 64k; # fastcgi_busy_buffers_size 128k; # fastcgi_temp_file_write_size 128k;  # gzip on; # gzip_min_length 1k; # gzip_buffers   4 16k; # gzip_http_version 1.0; # gzip_comp_level 2; # gzip_types    text/plain application/x-javascript text/css application/xml; # gzip_vary on;   #limit_zone crawler $binary_remote_addr 10m;  ###禁止通過ip訪問站點  server{     server_name _;     return 404;     }    server  {   listen    80;   server_name localhost;   index index.html index.htm index.jsp;#設定訪問的默認首頁地址   root /home/www/web/ROOT;#設定網站的資源存放路徑    #limit_conn  crawler 20;        location ~ .*.jsp$ #所有jsp的頁面均交由tomcat處理   {    index index.jsp;    proxy_pass http://localhost:8080;#轉向tomcat處理    }          location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$ #設定訪問靜態文件直接讀取不經過tomcat   {    expires   30d;   }    location ~ .*/.(js|css)?$   {    expires   1h;   }    #定義訪問日志的寫入格式    log_format access '$remote_addr - $remote_user [$time_local] "$request" '       '$status $body_bytes_sent "$http_referer" '       '"$http_user_agent" $http_x_forwarded_for';   access_log /usr/local/nginx/logs/localhost.log access;#設定訪問日志的存放路徑     }  } 

5、修改/usr/local/nginx/conf/nginx.conf配置文件后,請執行以下命令檢查配置文件是否正確:

#/usr/local/nginx/sbin/nginx -t

如果屏幕顯示以下兩行信息,說明配置文件正確: 

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

如果提示unknown host,則可在服務器上執行:ping www.baidu.com如果也是同樣提示unknown host則有兩種可能:

a、服務器沒有設置DNS服務器地址,查看/etc/resolv.conf下是否設置,若無則加上

b、防火墻攔截

 6、啟動nginx的命令

#/usr/local/nginx/sbin/nginx

這時,輸入以下命令查看Nginx主進程號:

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

7、停止nginx的命令

#/usr/local/nginx/sbin/nginx -s stop

8、在不停止Nginx服務的情況下平滑變更Nginx配置

a、修改/usr/local/nginx/conf/nginx.conf配置文件后,請執行以下命令檢查配置文件是否正確:

/usr/local/nginx/sbin/nginx -t

如果屏幕顯示以下兩行信息,說明配置文件正確:

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully

b、這時,輸入以下命令查看Nginx主進程號:

ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

屏幕顯示的即為Nginx主進程號,例如:

6302

這時,執行以下命令即可使修改過的Nginx配置文件生效:

kill -HUP 6302

或者無需這么麻煩,找到Nginx的Pid文件:

kill -HUP `cat /usr/local/nginx/nginx.pid`

9、nginx啟動好后啟動tomcat,此時輸入http://主機ip地址即可看到“My web!”

三、其他

stub_status

語法: stub_status on

默認值: None

作用域: location

創建一個 location 區域啟用 stub_status

“stub status” 模塊返回的狀態信息跟 mathopd's 的狀態信息很相似. 返回的狀態信息如下:

Active connections: 291server accepts handled requests 16630948 16630948 31070465Reading: 6 Writing: 179 Waiting: 106

active connections — 對后端發起的活動連接數

server accepts handled requests — nginx 總共處理了 16630948 個連接, 成功創建 16630948 次握手 (證明中間沒有失敗的), 總共處理了 31070465 個請求 (平均每次握手處理了 1.8個數據請求)

reading — nginx 讀取到客戶端的Header信息數

writing — nginx 返回給客戶端的Header信息數

waiting — 開啟 keep-alive 的情況下,這個值等于 active – (reading + writing),意思就是Nginx說已經處理完正在等候下一次請求指令的駐留連接

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 介休市| 达孜县| 永善县| 密云县| 双柏县| 武冈市| 澳门| 蓝田县| 昆明市| 姜堰市| 泰安市| 北安市| 云和县| 古交市| 襄汾县| 都兰县| 元氏县| 泉州市| 自贡市| 镇安县| 海伦市| 绿春县| 广东省| 阜新市| 遂宁市| 茂名市| 建德市| 个旧市| 台中县| 永兴县| 渭源县| 临夏市| 夏河县| 新巴尔虎右旗| 云浮市| 尼玛县| 缙云县| 荔浦县| 皮山县| 四子王旗| 柞水县|