nginx多页面配置
- 必须在location /mypass块中将root html替换为alias html
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /mypass {
alias html/mypass;
index index.html index.htm;
}
# 做请求转发
location /test {
proxy_pass https://www.baidu.com/;
}
}
server_name 的配置方式有三种,分别是:
- 精确匹配
- 通配符匹配
- 正则表达式匹配
精确匹配
server {
listen 80;
server_name www.zxy.com localhost;
}
通配符匹配
server_name 中支持通配符 “*”, 但需要注意的是通配符不能出现在域名的中间,只能出现在首段或尾段
server_name localhost www.zcy.*;
正则表达式配置
server_name 中可以使用正则表达式,并且使用 ~ 作为正则表达式字符串的开始标记
负载均衡