Nginx做静态资源服务器优于Tomcat

区分静态资源,动态资源请求

使用域名区分!

如果是动态资源请求  反向代理到 Tomcat

如果 是静态资源请求  直接走本地Nginx

配置:

###静态资源
server {
listen 80;
server_name static.toov5.com;
location /static/img {
root /home;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

女神出现了

动态:

properties:

server.port: 8080
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp  

controller

package com.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @SpringBootApplication
@Controller
public class IndexController { @RequestMapping("/")
public String index() {
System.out.println("index");
return "index";
} public static void main(String[] args) {
SpringApplication.run(IndexController.class, args);
} }

jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basepath %>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
</head>
<body>
<h1>
look:
<img alt="" src="http://static.toov5.com/static/img/p.jpg">
</h1>
</body>
</html>

pom:

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itmayiedu</groupId>
<artifactId>servet_demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<!-- SpringBoot 核心组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
</project>

  

我的访问url与 网页内嵌的不一样哦

访问时候是www    图片是static  完全分离了哦 哈哈哈

请求一次:

Nginx搭建动态静态服务器的更多相关文章

  1. 转:Linux下使用Nginx搭建简单图片服务器

    最近经常有人问图片上传怎么做,有哪些方案做比较好,也看到过有关于上传图片的做法,但是都不是最好的,今天再这里简单讲一下Nginx实现上传图片以及图片服务器的大致理念. 如果是个人项目或者企业小项目,仅 ...

  2. 腾讯云,搭建Http静态服务器环境

    任务时间:15min ~ 30min 搭建静态网站,首先需要部署环境.下面的步骤,将告诉大家如何在服务器上通过 Nginx 部署 HTTP 静态服务. 安装 Nginx 在 CentOS 上,可直接使 ...

  3. Nginx搭建flv视频点播服务器

    Nginx搭建flv视频点播服务器 前一段时间使用Nginx搭建的多媒体服务器只能在缓冲过的时间区域内拖放, 而不能拖放到未缓冲的地方. 这就带来了一个问题: 如果视频限速的速率很小, 那么客户端观看 ...

  4. 使用nginx搭建媒体点播服务器

    使用nginx搭建媒体点播服务器 最新由于兴趣,对ubuntu和安卓上的视频点播直播等应用比较感兴趣,所以在vmware的虚拟机里面搭建了一个视频点播网站,参考了fengzhanhai的文章Nginx ...

  5. nginx实现动态/静态文件缓存(week4_day1_part2)-技术流ken

    nginx实现静态文件缓存实战 1.nginx静态文件缓存 如果要熟练使用nginx来实现文件的缓存,那下面的几个指令你必须要牢记于心 指令1:proxy_cache_path 作用:设置缓存数据的相 ...

  6. django uWSGI nginx搭建一个web服务器 确定可用

    网上的找了很多篇 不知道为什么不行,于是自己搭建了一个可用的Web 大家可按步骤尝试 总结下基于uwsgi+Nginx下django项目生产环境的部署 准备条件: .确保有一个能够用runserver ...

  7. 使用Nginx搭建本地流媒体服务器

    Mac搭建nginx+rtmp服务器 1.打开终端,查看是否已经安装Homebrew,直接输入命令 man brew 如果Mac已经安装了, 会显示一些命令的帮助信息. 此时输入Q退出即可, 直接进入 ...

  8. nginx 搭建上传服务器

    nginx webdav 服务器搭建 该模块可以为Http webDAV 增加PUT,DELETE,MKCOL,COPY和MOVE等方法.模块在默认编译的情况下是不被包含的,需要指定编译 ./conf ...

  9. Nginx 搭建rtmp直播服务器

    1.到nginx源码目录新建个rtmp目录 ,进入  git clone https://github.com/arut/nginx-rtmp-module.git   2.重编译nginx 代码如下 ...

随机推荐

  1. Powershell - 获取服务器启动时间

    www.orangeisland.cn 使用以下命令,直接获取服务器启动时间: 通过以下脚本,批量获取服务器的启动时间: $TextPath = "C:\Users\admin\Deskto ...

  2. kotlin面向对象之枚举、印章类

    枚举: 由于这个比较简单,直接上代码: 下面使用一下: 印章类[Sealed class]: 听着挺新鲜的,下面以一个具体的场景来对它进行学习: 动物园里有三个动物如下,在天黑时它们污污的在做“游戏” ...

  3. python出现Non-ASCII character '\xe6' in file statistics.py on line 19, but no encoding declared错误

    可按照错误建议网址查看http://www.python.org/peps/pep-0263.html 发现是因为Python在默认状态下不支持源文件中的编码所致.解决方案有如下三种: 一.在文件头部 ...

  4. Machine Learn in Action(K-近邻算法)

    使用K-近邻算法将某点[0.6, 0.6]划分到某个类(A, B)中. from numpy import * import operator def classify0(inX, dataSet, ...

  5. SharpCompress 压缩解压

    public class SharpCompressHelper { public static void UnRAR(string srcUrl,string targetUrl) { using ...

  6. shiro之缓存

    1 细说shiro之七:缓存:https://www.cnblogs.com/nuccch/p/8044226.html 2 Shiro缓存使用Redis.Ehcache.自带的MpCache实现的三 ...

  7. 数组翻转的方法(java实现)

    数组翻转的方法(java实现),所谓数组翻转,就是将数组倒置,例如原数组为:{"a","b","c","d"},那么翻转 ...

  8. pgadmin4 csrf错误导致docker-compose postgres服务下线

    docker-compse up 启动的前台服务, 过一会就自动停止 检查半天,发现是pgadmin4没安装正确不断报400 和 csrf error 然后pgadmin4为啥报这个, 因为pytho ...

  9. POJ 1182食物链(并查集)

    食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 85474 Accepted: 25549Description动物王国中有三 ...

  10. Oracle11g RAC+DG搭建

    项目环境准备 3.1虚拟机配置 版本选择 注意Linux操作系统.此次项目我选择的版本是Oracle Enterprise Linux 5.4 内存的设置 本人电脑物理内存8G,由于此次实验要开三台虚 ...