最近又要准备新的项目架构,涉及到apache-tomcatcluster的相关问题,主要是以nginx+tomcat,博文为生成环境简化,重在架构思想。
准备安装环境,安装pcre,可以使用pcre源码或者rpm包安装
yum install -y pcre*
安装nginx
tarzxvfnginx-1.4.1.tar.gz
cdnginx-1.4.1/
./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module
make
makeinstall
nginx.conf配置
user nobody nobody; worker_processes 2; error_log /usr/local/nginx/logs/error.log crit; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #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; 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/access.log access; server { listen 80; server_name web1.example.com; index index.html index.htm index.php; root /usr/local/nginx/html; #limit_conn crawler 20; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { root /usr/local/nginx/html; expires 30d; } location ~ (\.jsp)|(\.do)$ { proxy_pass http://192.168.1.2:8080; proxy_redirect off; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 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; } location ~ .*\.(js|css)?$ { expires 1h; } } }
2、安装、配置tomcat
先安装jdk
rpm -ivh jdk-7u21-linux-i586.rpm
JAVA_HOME=/usr/java/jdk1.7.0_21 CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin export PATH CLASSPATH JAVA_HOME
安装tomcat
tar zxvf apache-tomcat-7.0.40.tar.gz cp -R apache-tomcat-7.0.40 /usr/local/tomcat
启动tomcat
/usr/local/tomcat/bin/startup.sh
<enginename="Catalina"defaultHost="localhost"> <hostname="localhost"appBase="webapps" unpackWARs="true"autoDeploy="true" xmlValidation="false"xmlNamespaceAware="false"> <host> </engine>
在<host></host>标签之间添加上:
<Contextpath=""docBase="html"debug="0"reloadable="true"/>
然后,修改$tomcat/conf/web.xml文件。
在web.xml文件中,有一段如下:
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:
<welcome-file>html</welcome-file>
在/usr/local/tomcat/webapps/html目录下新建一个index.jsp,一个index.do
然后在浏览器上访问静态页面index.html
在浏览器上访问动态页面index.jsp、index.do
本文出自 “老徐的私房菜” 博客,谢绝转载!