博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx+tomcat实现动静分离架构
阅读量:7096 次
发布时间:2019-06-28

本文共 3223 字,大约阅读时间需要 10 分钟。

最近又要准备新的项目架构,涉及到apache-tomcatcluster的相关问题,主要是以nginx+tomcat,博文为生成环境简化,重在架构思想。

准备安装环境,安装pcre,可以使用pcre源码或者rpm包安装

yum install -y pcre*

安装nginx

 
  1. tarzxvfnginx-1.4.1.tar.gz

  2. cdnginx-1.4.1/

  3. ./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module

  4. make

  5. 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
在/etc/profile里设置环境变量
JAVA_HOME=/usr/java/jdk1.7.0_21CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/libPATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/binexport PATH CLASSPATH JAVA_HOME
然后在source/etc/profile

安装tomcat

tar zxvf apache-tomcat-7.0.40.tar.gzcp -R apache-tomcat-7.0.40 /usr/local/tomcat

启动tomcat

/usr/local/tomcat/bin/startup.sh
之后打开http://localhost:8080就能看到tomcat的默认界面了
下面我们来修改tomcat的首页
我在$tomcat/webapps/下建了个html目录作为我网站的默认目录,在html中有一个index.html文件,该文件要作为我网站的默认主页。
首先,修改$tomcat/conf/server.xml文件。
在server.xml文件中,有一段如下

在<host></host>标签之间添加上:

path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;
docBase是虚拟目录的路径,它默认的是$tomcat/webapps/ROOT目录,现在我在webapps目录下建了一个html目录,让该目录作为我的默认目录。
debug和reloadable一般都分别设置成0和true。

然后,修改$tomcat/conf/web.xml文件。

在web.xml文件中,有一段如下:

index.html
index.htm
index.jsp

在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:

html

在/usr/local/tomcat/webapps/html目录下新建一个index.jsp,一个index.do

然后在浏览器上访问静态页面index.html

在浏览器上访问动态页面index.jsp、index.do

转载地址:http://uyxql.baihongyu.com/

你可能感兴趣的文章
瀑布流案例
查看>>
SSL证书绑定成功
查看>>
在sqlserver 中with(nolock)详解
查看>>
如何把网页变成灰色效果
查看>>
spring5 reactive
查看>>
try-with-resources语句
查看>>
Ubuntu下安装arm-linux-gnueabi-xxx编译器【转】
查看>>
bootstrap之 formgroup表单布局样式
查看>>
[k8s]svc里知识点小结
查看>>
响应式流API的构建基础
查看>>
thinkphp5项目--个人博客(三)
查看>>
WebStorm 之 Cordova 环境搭建
查看>>
Linux笔记
查看>>
Java并发编程_wait/notify和CountDownLatch的比较(三)
查看>>
固态硬盘(Solid State Drives)
查看>>
鹅厂优文|主播pk,如何实现无缝切换?
查看>>
Building an (awesome) API with NancyFX 2.0 + Dapper
查看>>
崔永元手撕范冰冰,小崔凭什么能赢?
查看>>
一个老鸟发的公司内部整理的 Android 学习路线图
查看>>
mount过程分析之一(基于3.16.3内核)【转】
查看>>