Maven&Nginx
Maven作用:构建项目,管理包。库:中央库,镜像库,私服,本地库。资源定位:<groupId><artifactId><version>配置:本地库,镜像库使用:命令行指令mvn archetype:generatemvn compile导入pom文件中指定的依赖将src/main目录下的源码和资源编译后存放到target/class...
Maven
作用:构建项目,管理包。
库:中央库,镜像库,私服,本地库。
资源定位:
<groupId>
<artifactId>
<version>
配置:本地库,镜像库
使用:命令行指令mvn archetype:generate
mvn compile
导入pom文件中指定的依赖
将src/main目录下的源码和资源编译后存放到target/classes下mvn test
mvn package
mvn clean
mvn install
项目安装,将打包好的包以及相关的资源文件放到本地库中,有maven进行管理。mvn deploy
将maven本地库中管理的资源发布到远程库中
依赖:
scope范围
compile:编译,打包,安装,发布都存在
test:测试
runtime:不参加编译
provided:编译
system: 系统范围
依赖传递:exclusion移除依赖传递关系
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
<exclusions>
<exclusion>
<!-- 坐标指定移除内容 -->
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.7.RELEASE</version>
</exclusion>
</exclusions>
</dependency>
插件:
main
在这里插入代码片
打源码:额外打包源码文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
eclipse
命令不写mvn,直接写目的。
目录结构
配置文件介绍
Pom.xml
web.xml
SSM的配置文件:
spring springmvc
Spring
applicationContext.xml
Spring MVC
springmvc.xml
Mybaits
sqlMapConfig.xml
userMapper.xml
Nginx
请求转发案例
当客户端访问http://www.pq.com时,由nginx转发给http://127.0.0.1:8080端口进行处理
配置hosts文件
http {
server {
#监听本机的80端口
listen 80;
#接收访问地址
server_name http://www.pq.com;
#对任意的访问路径进行处理
location /{
#转发到指定地址
proxy_pass http://127.0.0.1:8080;
}
}
- location路径配置和匹配规则 针对server_name
https://segmentfault.com/a/1190000019382897?utm_source=tag-newest
精确匹配 =
区分大小写 ~
不区分大小写 ~*
通用匹配 /
类似通用匹配 ^~
负载均衡
upstream demo1{
server 127.0.0.1:8081;
server 127.0.0.1:8082;
server 127.0.0.1:8083;
}
server{
listern 80;
server_name www.zjn.com;
location /{
proxy_pass http://demo1;
}
}
- 轮询 默认
- ip哈希
ip_hash;
- 最少连接
least_conn;
- 基于权重 在IP后面添加weight属性
动静分离
动态资源:servlet jsp。。程序
静态资源:jpg MP4 html 。。 文件
→静态资源不再通过tomcat(本质上就是为了处理动态资源设计的服务器)访问,使用nginx(只能处理静态资源且性能优良)处理。
server {
listen 80;
server_name www.staticfile.com;
location / {
//www.staticfile.com/aaa/bbb/1.html-->d://html/aaa/bbb/1.html
//root指向nginx服务器中的本地磁盘地址,静态文件就放置在这个磁盘地址。
root D://html;
//默认访问的首页配置
index index.html;
}
}
更多推荐
所有评论(0)