每个server代表一个虚拟主机
1个ip可以对应多个域名,在浏览器输入域名的时候先去访问本地hosts文件是否有对应关系,如果没有去DNS查找
windows/system32/driver/etc/hosts
server {
listen 80;–绑定端口
server_name www.lxtravel.com;绑定域名修改域名
location / {
root index;--指定虚拟目录
index index.html index.htm;--指定首页
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
域名映射
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.lxtravel.com;
location / {
root index;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name regist.lxtravel.com;
location / {
root regist;
index regist.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
正向代理:代理的客户端
反向代理:代理的服务端
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream tomcat-travel{
server 182.92.201.18:8080;
}
server {
listen 80;
server_name www.lxtravel.com;
location / {
#root index;
proxy_pass http://tomcat-travel;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
负载均衡
upstream tomcat-travel{
server 182.92.201.18:8080;
server 182.92.201.18:8081;
server 182.92.201.18:8080;
}
设置权重
upstream tomcat-travel{
server 182.92.201.18:8080 weight=2;
server 182.92.201.18:8081;
server 182.92.201.18:8080;
}