/ 中存储网

在Linux上安装配置Nginx与tomcat运行JSP

2013-12-27 15:11:01 来源:IT技术网
tomcat 和 JDK 的安装

1.1下载http://java.sun.com/javase/downloads/widget/jdk6.jsp

下载完成后修改jdk-6u17-linux-i586.bin属性

 chmod +x jdk-6u17-linux-i586.bin

 ./jdk-6u17-linux-i586.bin

mv  jdk-6u17-linux-i586.bin /usr/local/jdk

vi /etc/profile 

在文件末尾添加如下内容:

JAVA_HOME="/usr/local/jdk"

CLASS_PATH="$JAVA_HOME/lib:$FAVA_HOME/jre/lib"

PATH=".:$PATH:$JAVA_HOME/bin"

CATALINA_HOME="/usr/local/lnmp/tomcat"

export JAVA_HOME CATALINA_HOME

保存

source /etc/profile

1.2 下载JDK

http://apache.freelamp.com/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz

tar zxvf apache-tomcat-6.0.35.tar.gz

mv apache-tomcat-6.0.35 /usr/local/tomcat

cp -rf /usr/local/tomcat/webapps/* /date/www/

vi /usr/local/tomcat/conf/server.xml

查找appBase=”webapps” 修改为:appBase=”/date/www”,/date/www为网站的根目录

安装修改后,启动tomcat

/usr/local/tomcat/bin/startup.sh

netstat -ntl  看有没有8080

关闭 /usr/local/tomcat/bin/shutdown.sh

nginx 与 tomcat 配置

vi /usr/local/lnmp/nginx/conf/nginx.conf

user www www;

worker_process 8;

Worker_rlimit_nofile 65535;

Events

{

  use epoll;

  worker_connections 65535;

}

http

{

Include mime.types;

default_type application/octet-stream;

charset utf-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffer 4 32k;

client_max_body_size 300m;

sendfile on;

tcp_nopush on;

keepalive_timeout 5;

tcp_nodelay on;

client_body_buffer_size 512k;

proxy_connect_timeout 5;

proxy_read_timeout 60;

proxy_buffer_size 16k;

proxy_buffer 4 16k;

proxy_busy_buffers_size 128k;

proxy_temp_file_write_size 128k;

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.1;

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;

}

server

{

listen 80;

server_name localhost;

index index.html index.htm index.jsp default.jsp index.do default.do;

root /date/www;

if (-d $request_filename)

{

rewrite ^/(.*)([^/])$ http://$host/$1$2/  permanent;

}

location ~ .(jsp|jspx|do)?$ {

proxy_set_header Host $host;

proxy_set_header x-forwarded-for $remote_addr;

proxy_pass http://tomcat_server;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)?$

{

  expires 1h;  

}

access_log off;

  }

}

启动nginx

/usr/local/lnmp/nginx/sbin/nginx

/usr/local/lnmp/nginx/sbin/nginx -t  检查nginx.conf的配置文件语法

测试jsp

http://ip/examples/jsp/

Nginx与jsp(tomcat) 在linux上的安装与配置 - zenghui940 - zenghui940的博客

http://192.168.1.203:8080/manager/status 后台管理

Nginx与jsp(tomcat) 在linux上的安装与配置 - zenghui940 - zenghui940的博客