安装相关环境
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ ~]# yum install gcc-c++ |
下载nginx稳定版
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz |
启动成功测试
通过端口区分虚拟主机
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ nginx]# cp -r html/ html81 |
通过域名区分虚拟主机
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ nginx]# cp -r html/ html-xyz |
反向代理
1 | [root@iZuf6iq8e7ya9v3ix71k0pZ nginx]# vim conf/nginx.conf |
负载均衡
weight:设置对应服务器的权重,默认为11
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[root@iZuf6iq8e7ya9v3ix71k0pZ nginx]# vim conf/nginx.conf
upstream tomcat8081 {
server smniuhe.com:8081 weight=1;
server smniuhe.com:8083 weight=1;
}
server {
listen 80;
server_name smniuhe.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcat8081;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@iZuf6iq8e7ya9v3ix71k0pZ nginx]# sbin/nginx -s reload