CentOS? Nginx+jdk+tomcat 環(huán)境搭建??
一、jdk安裝
從上面網(wǎng)頁(yè)中選擇適合的jdk下載到/root/目錄下。我選擇的是jdk-6u20-linux-i586.bin。
下載完后,修改jdk-6u23-linux-i586.bin的文件屬性為可執(zhí)行,然后執(zhí)行該程序安裝JDK:
chmod +x jdk-6u20-linux-i586.bin
./ jdk-6u20-linux-i586.bin
按空格鍵看完協(xié)議,當(dāng)出現(xiàn)提示“Do you agree to the above license terms?[yes or no] ” 時(shí),輸入“yes”。安裝完成后,執(zhí)行以下語(yǔ)句:
mv jdk1.
6
.0_23 /usr/local/jdk
編輯profile文件 設(shè)置開(kāi)機(jī)文件java開(kāi)機(jī)執(zhí)行環(huán)境文件:
vi /etc/profile
在文件的末尾增加如下內(nèi)容:
JAVA_HOME= " /usr/local/jdk "
CLASS_PATH= " $JAVA_HOME/lib:$JAVA_HOME/jre/lib "
PATH= " $JAVA_HOME/bin:.:$PATH "
CATALINA_HOME= " /usr/local/tomcat "
export JAVA_HOME CATALINA_HOME
保存并退出vi,執(zhí)行以下命令使配置生效:
source /etc/profile
二、tomcat安裝
將?apache-tomcat-6.0.35 放到/root/目錄中,拷貝到/user/local/目錄下,并重命名為tomcat:
mv apache-tomcat- 6.0 . 23 /usr/local/tomcat
建立網(wǎng)頁(yè)根目錄:
mkdir /www
cp -rf /usr/local/tomcat/webapps /* /www/
配置tomcat的server.xml文件:
vim /usr/local/tomcat/conf/server.xml
查找appBase=”webapps”,修改為appBase=”/www”,其中/www 即為網(wǎng)頁(yè)的根目錄。
修改完成后,啟動(dòng)tomcat,默認(rèn)監(jiān)聽(tīng)端口為8080:
/usr/local/tomcat/bin/startup.sh
停止tomcat可以使用以下命令:
/usr/local/tomcat/bin/shutdown.sh
注:在執(zhí)行./startup.sh,或者./shutdown.sh的時(shí)候,爆出了Permission denied,
其實(shí)很簡(jiǎn)單,就是在執(zhí)行tomcat的時(shí)候,用戶(hù)沒(méi)有權(quán)限,而導(dǎo)致無(wú)法執(zhí)行,
用命令chmod 修改一下bin目錄下的.sh權(quán)限就可以了:
chmod u+x *.sh
再次執(zhí)行 /usr/local/tomcat/bin/startup.sh (或/usr/local/tomcat/bin/shutdown.sh)就可以了。
?三、nginx與tomcat整合?
Nginx與tomcat的整合其實(shí)就是只要配置好nginx.conf文件就可以了。
查看并修改nginx.conf文件:
vim /usr/local/nginx/conf/nginx.conf
修改后的nginx.conf文件,紅色部分為添加的關(guān)于tomcat的代碼:
user www www;
worker_processes 1 ;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200 ;
events
{
use epoll;
worker_connections 51200 ;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128 ;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60 ;
tcp_nodelay on;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
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 256k;
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;
upstream tomcat_server {
server 127.0.0.1:8080;
}
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80 ;
server_name www.test.com;
index index.html index.htm index.jsp index. do default .jsp default . do index.php;
root /home/wwwroot;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$http://$host/$1$2/ permanent;
}
location ~ \.(jsp|jspx|do|wsdl)?$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_server;
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
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 /home/wwwlogs/access.log access;
}
include vhost /* .conf;
}
在配置文件中,靜態(tài)HTML網(wǎng)頁(yè)、圖片、js、css、Flash等使用Nginx來(lái)處理,以便得到更快的速度,文件擴(kuò)展名為.JSP、.do、wsdl的請(qǐng)求,由Nginx反向代理Tomcat HTTP服務(wù)器來(lái)處理。
修改/usr/local/nginx/conf/nginx.conf配置文件后,請(qǐng)執(zhí)行以下命令檢查配置文件是否正確:
/usr/local/nginx/sbin/nginx -t
如果屏幕顯示以下兩行信息,說(shuō)明配置文件正確:
?
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
重新啟動(dòng)nginx:
/usr/local/nginx/sbin/nginx -s reload
nginx啟動(dòng)后,可以訪(fǎng)問(wèn)以下URL中的jsp實(shí)例程序,檢查jsp程序能否運(yùn)行。
http://localhost/examples/jsp/
注意:nginx與tomcat的工作原理是由nginx代理tomcat輸出網(wǎng)頁(yè),因此如果開(kāi)啟了防火墻,防火墻不用打開(kāi)8080端口,也一樣可以訪(fǎng)問(wèn)jsp頁(yè)面。
?
?
?
?
本文內(nèi)容參考如下網(wǎng)址:
http://www.cnblogs.com/huangjingzhou/articles/2153405.html
http://blog.163.com/leijie131421@126/blog/static/424111452011228103243106/
http://blog.slogra.com/?post=28
http://hi.baidu.com/wptad/blog/item/d3d33b019b0741147bec2cea.html
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
