标签:tab 代理 log cat main str 域名 img 分享
1.http服务器
2.虚拟主机
3.反向代理,负载均衡
安装nginx
配置虚拟主机:
/usr/local/nginx/conf/nginx.conf
一个server就是一个虚拟主机
1.通过端口访问
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
server { listen 81; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
2.共用80端口,通过域名访问
server { listen 80; server_name www.jd.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } } server { listen 80; server_name www.taobao.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
反向代理:
启动两个tomcat:
upstream tomcat1 { server 192.168.25.148:8080; } server { listen 80; server_name www.sina.com.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat1; index index.html index.htm; } } upstream tomcat2 { server 192.168.25.148:8081; } server { listen 80; server_name www.sohu.com; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat2; index index.html index.htm; } }
负载均衡:
再启动一个tomcat,修改端口为8082,
访问www.sohu.com会轮询访问 weight=2的请求次数越多
upstream tomcat2 { server 192.168.25.148:8081; server 192.168.25.148:8082 weight=2;
} server { listen 80; server_name www.sohu.com; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://tomcat2; index index.html index.htm; } }
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
|
location / {
root html;
index index.html index.htm;
}
}
标签:tab 代理 log cat main str 域名 img 分享
原文地址:https://www.cnblogs.com/zhoucx66/p/9269700.html