nginx能够从新加载文件的。咱们直接运行:nginx -s reload css
配置文件有没有问题,能够直接输入:nginx -thtml
nginx -s stop就能够关闭java
但有时咱们就不想它挂的时候访问另一个,而只是但愿一个服务器访问的机会比另一个大,使用weightnginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#gzip on;
#一个服务器挂了,多配置一个jetty,weight=数字来指定,数字越大,代表请求到的机会越大
upstream local_tomcat {
server localhost:
8080
weight=
1
;
server localhost:
9999
weight=
5
;
server{
listen
8030
;
server_name localhost:
8080
;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {proxy_pass http:
//local_tomcat;}
##......其余省略
#过滤不一样的jsp和静态html页面
#location / { proxy_pass http:
//localhost:8080;}
#location ~ .jsp$ { proxy_pass http:
//localhost:8080;}
#location ~ .(html|js|css|png|gif)$ { root D:/apache-tomcat-
7.0
.
77
/webapps/ROOT;}
error_page
500
502
503
504
/50x.html;
location = /50x.html {
root html;
}
}
|
一、nginx能作反向代理,那么什么是反向代理呢,举个栗子,我想在本地使用 www.mickey.com 的域名去访问 www.taobao.com。那么这个时候咱们就能够经过nginx去实现。web
二、nginx能实现负载均衡,什么是负载均衡呢?就是个人项目部署在不一样的服务器上,可是经过统一的域名进入,nginx则对请求进行分发,减轻了服务器的压力。redis
三、做为安全隔离的做用;apache
四、解决跨域问题。跨域
五、缓存静态文件,加快访问速度。缓存
修改nginx.conf 配置文件,启用 upstream 负载均衡 tomcat Cluster,默认使用轮询方式。tomcat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
upstream site {
server localhost:
8080
;
server localhost:
9090
;
}
server {
listen
80
;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
index index_tel.jsp index.jsp index.html index.htm ;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffers
32
4k;
proxy_connect_timeout
3
;
proxy_send_timeout
30
;
proxy_read_timeout
30
;
proxy_pass http:
//site;
}
|
测试:
一、访问 http://10.129.221.70:8080 直接请求到tomcat_1服务器,显示 “ response from tomcat_1 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;
二、访问 http://10.129.221.70:9090 直接请求到tomcat_2服务器,显示 “ response from tomcat_2 ”, session 值为 ‘56E2FAE376A47F1C0961D722326B8423’;
三、访问 http://10.129.221.70 (默认80端口)请求到 nginx 反向代理到指定Web服务器,因为默认使用轮询负载方式,反复刷新页面显示的内容在“ response from tomcat_1 ” 和 “ response from tomcat_2 ”之间切换,但 session 值保持为 ‘56E2FAE376A47F1C0961D722326B8423’;
四、使用 redis-cli 链接 redis 服务器,查看会显示有 “56E2FAE376A47F1C0961D722326B8423” key的 session 数据,value为序列化数据。