worker_processes 1;#工作进程的个数,一般与计算机的cpu核数一致
events {
worker_connections 1024;#单个进程最大连接数(最大连接数=连接数*进程数)
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型
sendfile on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
keepalive_timeout 65; #长连接超时时间,单位是秒
gzip on;#启用Gizp压缩
#服务器的集群
# upstream netitcast.com { #服务器集群名字
# server localhost:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
# server localhost:8082 weight=1;
# server localhost:8090 weight=1;
# }
#当前的Nginx的配置
server {
listen 8001;#监听8001端口,可以改成其他端口
server_name localhost;############## 当前服务的域名
location /i/ {
root C:/image/; ## 要与服务器的集群 名称一样
autoindex on;
expires 24h; #缓存设置过期时间
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
一个nginx服务器配置负载均衡和动静分离(80)。一个nginx图片服务器(8001)。三个tomcat服务器(8081,8082,8090)。
###
一。图片服务器配置:
在C盘建立图片目录,C:\image\i\abc.jpg
nginx图片服务器配置
##############################
worker_processes 1;#工作进程的个数,一般与计算机的cpu核数一致
events {
worker_connections 1024;#单个进程最大连接数(最大连接数=连接数*进程数)
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型
sendfile on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
keepalive_timeout 65; #长连接超时时间,单位是秒
gzip on;#启用Gizp压缩
#服务器的集群
# upstream netitcast.com { #服务器集群名字
# server localhost:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
# server localhost:8082 weight=1;
# server localhost:8090 weight=1;
# }
#当前的Nginx的配置
server {
listen 8001;#监听8001端口,可以改成其他端口
server_name localhost;############## 当前服务的域名
location /i/ {
root C:/image/; ## 要与服务器的集群 名称一样
autoindex on;
expires 24h; #缓存设置过期时间
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
###################################
访问http://localhost/i/abc.jpg可访问到图片。。。。。
二、nginx服务器配置负载均衡和动静分离配置
配置文件:
worker_processes 1;#工作进程的个数,一般与计算机的cpu核数一致
events {
worker_connections 1024;#单个进程最大连接数(最大连接数=连接数*进程数)
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型
sendfile on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
keepalive_timeout 65; #长连接超时时间,单位是秒
gzip on;#启用Gizp压缩
#服务器的集群
upstream netitcast.com { #服务器集群名字
server localhost:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server localhost:8082 weight=1;
server localhost:8090 weight=1;
}
#图片服务器的集群
upstream netitcastimg.com {
server localhost:8001 weight=1;
}
#当前的Nginx的配置
server {
listen 80;#监听80端口,可以改成其他端口
server_name localhost;############## 当前服务的域名
location / {
proxy_pass http://netitcast.com; ## 要与服务器的集群 名称一样
proxy_redirect default;
}
location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
proxy_pass http://netitcastimg.com;
expires 30d; ##缓存30天
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
三、JSP文件 IMG <img src="/i/abc.jpg" alt="上海鲜花港 - 郁金香" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body>
home.html
<p th:text="${#httpServletRequest.getParameter('account')}"></p>
<div th:text="${session.account}"></div>
<img src="/i/abc.jpg" alt="上海鲜花港 - 郁金香" />
</body>
</html>
th:text thymeleaf标签
四、访问 http://localhost展示home.html显示图片
worker_processes 1;#工作进程的个数,一般与计算机的cpu核数一致
events {
worker_connections 1024;#单个进程最大连接数(最大连接数=连接数*进程数)
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream;#默认文件类型
sendfile on;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
keepalive_timeout 65; #长连接超时时间,单位是秒
gzip on;#启用Gizp压缩
#服务器的集群
upstream netitcast.com { #服务器集群名字
server localhost:8081 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server localhost:8082 weight=1;
server localhost:8090 weight=1;
}
#图片服务器的集群
upstream netitcastimg.com {
server localhost:8001 weight=1;
}
#当前的Nginx的配置
server {
listen 80;#监听80端口,可以改成其他端口
server_name localhost;############## 当前服务的域名
location / {
proxy_pass http://netitcast.com; ## 要与服务器的集群 名称一样
proxy_redirect default;
}
location ~ .*\.(js|css|ico|png|jpg|eot|svg|ttf|woff) {
proxy_pass http://netitcastimg.com;
expires 30d; ##缓存30天
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}