Nginx搭建动态静态服务器
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搭建动态静态服务器的更多相关文章
- 转:Linux下使用Nginx搭建简单图片服务器
最近经常有人问图片上传怎么做,有哪些方案做比较好,也看到过有关于上传图片的做法,但是都不是最好的,今天再这里简单讲一下Nginx实现上传图片以及图片服务器的大致理念. 如果是个人项目或者企业小项目,仅 ...
- 腾讯云,搭建Http静态服务器环境
任务时间:15min ~ 30min 搭建静态网站,首先需要部署环境.下面的步骤,将告诉大家如何在服务器上通过 Nginx 部署 HTTP 静态服务. 安装 Nginx 在 CentOS 上,可直接使 ...
- Nginx搭建flv视频点播服务器
Nginx搭建flv视频点播服务器 前一段时间使用Nginx搭建的多媒体服务器只能在缓冲过的时间区域内拖放, 而不能拖放到未缓冲的地方. 这就带来了一个问题: 如果视频限速的速率很小, 那么客户端观看 ...
- 使用nginx搭建媒体点播服务器
使用nginx搭建媒体点播服务器 最新由于兴趣,对ubuntu和安卓上的视频点播直播等应用比较感兴趣,所以在vmware的虚拟机里面搭建了一个视频点播网站,参考了fengzhanhai的文章Nginx ...
- nginx实现动态/静态文件缓存(week4_day1_part2)-技术流ken
nginx实现静态文件缓存实战 1.nginx静态文件缓存 如果要熟练使用nginx来实现文件的缓存,那下面的几个指令你必须要牢记于心 指令1:proxy_cache_path 作用:设置缓存数据的相 ...
- django uWSGI nginx搭建一个web服务器 确定可用
网上的找了很多篇 不知道为什么不行,于是自己搭建了一个可用的Web 大家可按步骤尝试 总结下基于uwsgi+Nginx下django项目生产环境的部署 准备条件: .确保有一个能够用runserver ...
- 使用Nginx搭建本地流媒体服务器
Mac搭建nginx+rtmp服务器 1.打开终端,查看是否已经安装Homebrew,直接输入命令 man brew 如果Mac已经安装了, 会显示一些命令的帮助信息. 此时输入Q退出即可, 直接进入 ...
- nginx 搭建上传服务器
nginx webdav 服务器搭建 该模块可以为Http webDAV 增加PUT,DELETE,MKCOL,COPY和MOVE等方法.模块在默认编译的情况下是不被包含的,需要指定编译 ./conf ...
- Nginx 搭建rtmp直播服务器
1.到nginx源码目录新建个rtmp目录 ,进入 git clone https://github.com/arut/nginx-rtmp-module.git 2.重编译nginx 代码如下 ...
随机推荐
- 安全专家发现GE Multilin SR的一个关键漏洞对全球电网构成严重威胁。
A team of researchers from New York University has found a serious vulnerability in some of GE Multi ...
- 如何自己搭建DNS服务器
DNS服务器是计算机域名系统 (Domain Name System 或Domain Name Service) 的缩写,它是由 解析器和域名服务器组成的.域名服务器是指保存有该网络中所有主机的域名和 ...
- Transformer, ELMo, GPT, 到Bert
RNN:难以并行 CNN:filter只能考虑局部的信息,要叠多层 Self-attention:可以考虑全局的信息,并且可以并行 (Attention Is All You Need) 示意图:x1 ...
- java8学习之自定义收集器实现
在上次花了几个篇幅对Collector收集器的javadoc进行了详细的解读,其涉及到的文章有: http://www.cnblogs.com/webor2006/p/8311074.html htt ...
- 使用ajax向服务端发送Form中的数据
前端代码: <form action="" id="myFormUpdate"> <p>宠物名称: <input type=&qu ...
- hiho #1038 : 01背包 (dp)
#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...
- Python&R:警告信息管理
计算机程序有时很人性化,比如给你警告提示信息: 计算机程序有时又非常不人性化,比如动不动就给你警告提示...... 如果你的程序是要给客户使用,有运行美化要求: 再尤其是比如警告出现在循环里的情况,那 ...
- shell学习——关于shell函数库的使用
shell函数库的理解: 个人理解,shell函数库实质为一个脚本,脚本内包含了多个函数(函数具有普遍适用性). shell函数库的调用: 通过 . /path/lib/file.lib 或者 so ...
- Java中截取字符串中小数点前面的字符
通过下标获取 String number = "2563.2154"; int index = number.indexOf("."); String intN ...
- 冒泡排序和选择排序(bubble sort and selection sort)
Bubble sort Basic Method: import random nums = [random.randint(1,20) for _ in range(10)] #制作一个无序数字列表 ...