Tomcat是我们经常用的服务器,轻便快捷,但是数据量大的时候,会影响访问、响应速度,这时Nginx就出现了。

Nginx可做反向代理、负载均衡、动态与静态资源的分离的工作,这里我们就用它来做动静分离

动就是动态页面

静就是不改变或者不经常改变的文件,如:css、js和图片等

首先安装Nginx

下载地址http://nginx.org/en/download.html,我这里下载的是1.12.2版本,然后解压到E盘

cmd切换到nginx的目录下,输入start nginx或者nginx.exe,之后就可以在资源管理器中看到nginx.exe进程了,

直接在浏览器地址栏输入网址 http://localhost:80,回车,出现以下页面说明启动成功

配置Nginx

打开nginx文件conf下的nginx.conf配置文件,进行修改

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #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; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
#请求转发到tomcat,我的端口号是8888
proxy_pass http://localhost:8888;
index ak47.html index.html index.htm;
} # 动态请求的转发
location ~ \.(jsp|do)$ {
proxy_pass http://localhost:8888;
proxy_set_header Host $host;
}
# 静态请求直接读取
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
#静态资源地址
root E:/nginx/nginx-1.12./static; #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力 expires 1d;
}
error_page /50x.html;
location = /50x.html {
root html;
} } }

然后把项目的war放在tonmcat的webapps文件下

因为我的动态页面是放在SSM文件夹里面,所有我的静态资源也要放到

E:/nginx/nginx-1.12.2/static下的SSM文件夹下,通俗的来说就是把webapps里SSM项目下的style和public文件夹剪切到
E:/nginx/nginx-1.12.2/static的SSM下就可以了,不然无法访问静态资源。
 

最新文章

  1. java .bat批处理(java cmd命令)
  2. php mkdir函数
  3. apple 官方文档 Push Notification Programming
  4. iOS开发基础知识:Core Animation(核心动画)
  5. c#中网络异常的处理办法
  6. poj 2262 Goldbach's Conjecture(素数筛选法)
  7. php设计模式之简单工厂模式
  8. Andy's First Dictionary
  9. ios至于理解锚
  10. 学习的Python教程中的一些问题
  11. ●POJ 2284 That Nice Euler Circuit
  12. python -- 返回函数、匿名函数、装饰器
  13. 记录下自己VUE项目用Hbuider打包后启动白屏问题
  14. Oil Deposit
  15. 扁平化promise调用链(译)
  16. 多个string数组组装成一个List<Object>
  17. ubuntu源码安装jdk8
  18. Oracle存储过程的调试
  19. 【洛谷P2607】骑士 没有上司的舞会+
  20. Rpgmakermv(18)GALV RollCredits

热门文章

  1. Data Structure Binary Tree: Check if a given Binary Tree is SumTree
  2. codeforces 686B
  3. mysql 在windows server下发生系统错误 1067, 进程意外终止的解决方法
  4. EntityFramework 学习 一 DBEntityEntry
  5. BAT系列(一)— CNN
  6. director.js实现前端路由
  7. 一个可以拖拽的div
  8. SQL语言方方面面
  9. android开发中图片优化步骤
  10. Sqlite表结构读取工具,word批量转html,在线云剪贴板,文件批量提取工具;