2012年(28)
分类: LINUX
2012-05-29 19:50:40
Nginx+tomcat静态分离
Nginx的安装
tar -zxvf pcre-8.30.tar.gz
cd pcre-8.30
ntpdate time.windows.com
./configure
make
make install
groupadd www
useradd www -g www
yum install -y openssl-devel
tar -zxvf nginx-1.2.0.tar.gz
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
make
make install
NGINX 配置文件
user www www;
worker_processes 8;
pid /usr/local/nginx/logs/nginx.pid;
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 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 16;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server
{
listen 80;
server_name 192.168.88.145;
root /usr/local/nginx/html;
index index.html index.htm index.php index.jsp index.do;
location ~ \.(jsp|jspdx|do)?$ { #所有的jsp页面转交由tomcat处理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass ; #转向tomcat处理
}
Location~ .*\.(htm|html|gif|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ { #设置静态网页直接由nginx进行处理
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 /data/logs/access.log access;
}
}
与tomcat整合:
软件包:
jdk-7-linux-i586-rpm.bin
apr-util-1.3.12.tar.gz
apache-tomcat-7.0.27.tar.gz
apr-1.4.5.tar.gz
tar –zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure
Make
Make install
Tar –zxvf apr-util-1.3.12.tar.gz
./configure --with-apr=/usr/local/apr
Make
Make install
./ jdk-7-linux-i586-rpm.bin
Rpm –ivh jdk-7-linux-i586-rpm
Tar –zxvf apache-tomcat-7.0.27.tar.gz
cp –a apache-tomcat-7.0.27 /usr/local/tomcat
vi /etc/profile
在最后加:
export JAVA_HOME="/usr/java/jdk1.7.0/"
export PATH="$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin"
export CLASSPATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
export CATALINA_HOME="/usr/local/tomcat"
保存退出后
export /etc/profile
Tomcat配置文件
找到下面内容,并改成
unpackWARs="true" autoDeploy="true">
然后直接访问:,就可以看到jsp网页了