此文章压缩软件全部解压在/root下,文章红色字体为需要添加的内容

下载软件包:jdk-6u20-linux-i586.binnginx-1.0.8.tar.gzpcre-8.10.tar.gz apache-tomcat-6.0.18.tar.gz

[root@localhost ~]# ls
anaconda-ks.cfg install.log jdk-6u12-dlj-linux-i586.bin 
apache-tomcat-6.0.18.tar.gz install.log.syslog pcre-8.10.tar.gz
Desktop nginx-1.0.8.tar.gz 
[root@localhost ~]# vim /etc/hosts
192.168.0.160 www.lxxxker.com
[root@localhost ~]# host name www.lxxxker.com #临时生效
[root@localhost ~]# tar zxvf apache-tomcat-6.0.18.tar.gz 
[root@localhost ~]# mv apache-tomcat-6.0.18 tomcat
[root@localhost ~]# chmod -R 777 tomcat/
[root@localhost ~]# chmod +x jdk-6u12-dlj-linux-i586.bin 
[root@localhost ~]# ./jdk-6u12-dlj-linux-i586.bin 
[root@localhost ~]# vi /etc/profile
JAVA_HOME="/root/jdk1.6.0_12"
export JAVA HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
[root@localhost ~]# sh /etc/profile
[root@localhost ~]# tomcat/bin/startup.sh 
[root@localhost ~]# ps -ef |grep tomcat
[root@localhost ~]# tomcat/bin/shutdown.sh
[root@localhost ~]# tomcat/bin/startup.sh

输入网址:http://localhost:8080进行测试,如果看到猫为成功

Nginx+Tomcat实现动静分离_nginx+tomcat动静分离

把网页修改成自己想要的内容,做如下操作

[root@localhost ~]# mkdir -p /home/web 
[root@localhost ~]# vim tomcat/conf/server.xml 
126 <Host name="localhost" appBase="/home/web" (将网站根目录改为/home/web)
[root@localhost web]# cd /home/web/
[root@localhost web]# mkdir ROOT/
[root@localhost web]# cd ROOT/
[root@localhost ROOT]# echo " My web 1" > index.jsp 将网页显示的内容改为"My web 1"

[root@localhost ROOT]# cd

[root@localhost ~]# tar zxvf pcre-8.10.tar.gz
[root@localhost ~]# cd pcre-8.10
[root@localhost pcre-8.10]# ./configure ;make ;make install
[root@localhost ~]# tar zxvf nginx-1.0.8.tar.gz 
[root@localhost ~]# cd nginx-1.0.8
[root@localhost ~]# ./configure --with-http_stub_status_module --with-http_ssl_module ;make ;make install
[root@localhost ~]# chmod -R 777 /usr/local/nginx/
[root@localhost ~]# cd /usr/local/nginx/
[root@localhost ~]# cd /usr/local/nginx/
[root@localhost nginx]# cd conf/
[root@localhost conf]# vim proxy.conf #反向代理(负载均衡)规则
proxy_redirect off; #代理重定向关闭
proxy_set_header Host $host; #header头中获取的主机名

proxy_set_header X-Real-IP $remote_addr; #从header头中获取的主机的真实ip

proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for; #从header头中获取代理服务器的真实ip
client_max_body_size 300m; #允许客户端请求的最大单个文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大文件字节数
proxy_connect_timeout 90; #跟后端服务器连接超时时间发起握手等待响应超时时间
proxy_send_timeout 90; #后端服务器数据回传时间,就是在规定时间内后端服务器必须传完所有数据
proxy_read_timeout 90; #连接成功后_等待后端服务器响应时间_其实已经进入后端的排队之中等待处理
proxy_buffer_size 4k; #设置请求缓存区_这个缓存区会保存用户的头信息以供nginx进行规则处理_一般只要能保存下头信息即可
proxy_buffers 4 32k; #告诉nginx保存单个用的几个Buffer最大用多少空间
proxy_busy_buffers_size 64k; #代理忙碌时使用的缓冲区大小
proxy_temp_file_write_size 64k; #缓存临时文件的大小
proxy_intercept_errors on; #开启代理错误拦截功能

error_log logs/error.log; #错误日志存放位置
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid logs/nginx.pid; #进程号存放位置

worker_rlimit_nofile 65535; #一个nginx进程打开的最大文件数


http { #设置http服务器
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型
include /usr/local/nginx/conf/proxy.conf; #反向代理(负载均衡)配置文件
server_names_hash_bucket_size 128; #服务器名字的哈希存储大小
client_header_buffer_size 32k; #客户机上传文件缓存大小
large_client_header_buffers 4 32k; #设置请求缓冲
#client_max_body_size 8m; 

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; #定义访问日志的写入格式

access_log logs/access.log main; #nginx日志文件存放位置

sendfile on; #开启高效文件传输模式
tcp_nopush on; 
#防止网络阻塞

#keepalive_timeout 0;
keepalive_timeout 65; #指定客户端存活超时时间
tcp_nodelay on; #防止网络阻塞

#gzip on; #gzip压缩根据需要,可写可不行(默认没开启)

gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本
gzip_comp_level 7; #压缩比率
gzip_types text/plain application/json application/x-javascript text/css application/xml; #压缩类型
gzip_vary on; #vary header支持
limit_zone crawler $binary_remote_addr 10m; #目录限速 

server { #定义虚拟主机
listen 80; #监听的端口或ip
server_namewww.lxxxker.com#服务名
index index.html index.htm index.jsp; #默认网站首页
root /home/www/web/ROOT; 
#nginx网站根目录
#charset koi8-r;

#access_log logs/host.access.log main;
location ~ .*.jsp$ { #所有的jsp页面均交给tomcat处理
index index.jsp; 
proxy_pass 
http://localhost:8080
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #设定访问静态文件直接读取不经过tomcat
expires 30d; 
}
location ~ .*\.(js|css)?$ {
expires 1h; 
}