nginx配置:server_name的作用
2018-10-03 11:00
411 查看
[h1]作用[http://blog.csdn.net/h1]
[p]server name 为虚拟服务器的识别路径。因此不同的域名会通过请求头中的HOST字段,匹配到特定的server块,转发到对应的应用服务器中去。[http://blog.csdn.net/p]
[p] [http://blog.csdn.net/p]
[h1]案例[http://blog.csdn.net/h1]
[p]修改nginx.conf[http://blog.csdn.net/p]
[code]
[code]server {
listen 80;
server_name www;
location http://blog.csdn.net/ {
default_type texthttp://blog.csdn.net/html;
content_by_lua '
ngx.say("<p>first<http://blog.csdn.net/p>")
';
}
}
server {
listen 80;
server_name www.zkh.com;
location http://blog.csdn.net/ {
default_type texthttp://blog.csdn.net/html;
content_by_lua '
ngx.say("<p>second<http://blog.csdn.net/p>")
';
}
}
server {
listen 80;
server_name www.zkh.*;
location http://blog.csdn.net/ {
default_type texthttp://blog.csdn.net/html;
content_by_lua '
ngx.say("<p>third<http://blog.csdn.net/p>")
';
}
}
server {
listen 80;
server_name ~\w+.com;
location http://blog.csdn.net/ {
default_type texthttp://blog.csdn.net/html;
content_by_lua '
ngx.say("<p>forth<http://blog.csdn.net/p>")
';
}
}
server {
listen 80;
server_name ~.*zkh.com;
location http://blog.csdn.net/ {
default_type texthttp://blog.csdn.net/html;
content_by_lua '
ngx.say("<p>fifth<http://blog.csdn.net/p>")
';
}
}[http://blog.csdn.net/code]
[p]修改hosts文件[http://blog.csdn.net/p]
[code]
[code]118.126.100.138 www.zkh.com
118.126.100.138 www.zkh.org
118.126.100.138 zkh.com
118.126.100.138 zkh.org[http://blog.csdn.net/code]
[p]
[img]https:http://blog.csdn.net/http://blog.csdn.net/img-blog.csdn.nethttp://blog.csdn.net/20181003105620903?watermarkhttp://blog.csdn.net/2http://blog.csdn.net/texthttp://blog.csdn.net/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NoZW5nX0tvaHVphttp://blog.csdn.net/fonthttp://blog.csdn.net/5a6L5L2Thttp://blog.csdn.net/fontsizehttp://blog.csdn.net/400http://blog.csdn.net/fillhttp://blog.csdn.net/I0JBQkFCMA==http://blog.csdn.net/dissolvehttp://blog.csdn.net/70[http://blog.csdn.net/img]
[http://blog.csdn.net/p]
[p] [http://blog.csdn.net/p]
[p]
[img]https:http://blog.csdn.net/http://blog.csdn.net/img-blog.csdn.nethttp://blog.csdn.net/20181003105644788?watermarkhttp://blog.csdn.net/2http://blog.csdn.net/texthttp://blog.csdn.net/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NoZW5nX0tvaHVphttp://blog.csdn.net/fonthttp://blog.csdn.net/5a6L5L2Thttp://blog.csdn.net/fontsizehttp://blog.csdn.net/400http://blog.csdn.net/fillhttp://blog.csdn.net/I0JBQkFCMA==http://blog.csdn.net/dissolvehttp://blog.csdn.net/70[http://blog.csdn.net/img]
[http://blog.csdn.net/p]
[p]通过jmeter查看请求头,发现请求头携带了Host,由此可知nginx必定会拿它做uri匹配工作[http://blog.csdn.net/p]
[p]
[img]https:http://blog.csdn.net/http://blog.csdn.net/img-blog.csdn.nethttp://blog.csdn.net/20181003105727964?watermarkhttp://blog.csdn.net/2http://blog.csdn.net/texthttp://blog.csdn.net/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0NoZW5nX0tvaHVphttp://blog.csdn.net/fonthttp://blog.csdn.net/5a6L5L2Thttp://blog.csdn.net/fontsizehttp://blog.csdn.net/400http://blog.csdn.net/fillhttp://blog.csdn.net/I0JBQkFCMA==http://blog.csdn.net/dissolvehttp://blog.csdn.net/70[http://blog.csdn.net/img]
[http://blog.csdn.net/p]
[h1]匹配顺序[http://blog.csdn.net/h1]
[p]server_name与host匹配优先级如下:[http://blog.csdn.net/p]
[p]1、完全匹配[http://blog.csdn.net/p]
[p]2、通配符在前的,如*.test.com[http://blog.csdn.net/p]
[p]3、在后的,如[url=http://blog.csdn.net/]www.test.*[http://blog.csdn.net/url][http://blog.csdn.net/p]
[p]4、正则匹配,如~^\.www\.test\.com$[http://blog.csdn.net/p]
[p]如果都不匹配[http://blog.csdn.net/p]
[p]1、优先选择listen配置项后有default或default_server的[http://blog.csdn.net/p]
[p]2、找到匹配listen端口的第一个server块[http://blog.csdn.net/p]
[p] [http://blog.csdn.net/p]
[p] [http://blog.csdn.net/p]
[p]参考:1.[url=http://blog.csdn.net/cheng_kohui/article/details/https:http:/blog.csdn.net/http:/blog.csdn.net/blog.csdn.nethttp:/blog.csdn.net/LYLLOADhttp:/blog.csdn.net/articlehttp:/blog.csdn.net/detailshttp:/blog.csdn.net/79089410]为什么要配置nginx的servername[http://blog.csdn.net/url][http://blog.csdn.net/p]
[p] 2.[url=http://blog.csdn.net/cheng_kohui/article/details/https:http:/blog.csdn.net/http:/blog.csdn.net/www.cnblogs.comhttp:/blog.csdn.net/wangzhisduhttp:/blog.csdn.net/phttp:/blog.csdn.net/7839109.html]nginx中server的匹配顺序[http://blog.csdn.net/url][http://blog.csdn.net/p]
阅读更多
相关文章推荐
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- Nginx ServerName 配置说明(转)
- 详解Nginx虚拟主机配置中server_name的具体写法
- centos nginx server_name 配置域名访问规则
- Nginx server_name 参数配置
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- Nginx技巧:灵活的server_name,Nginx配置一个服务器多个站点 和 一个站点多个二级域名
- Nginx server_name 如何配置二级域名
- nginx servername配置域名网站可以正常登录,servername配置IP+Port却无法正常登录
- nginx配置server name
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- nginx 配置的server_name参数(转)
- nginx 配置的server_name参数(转)
- nginx server中的server_name配置的域名在客户机上无法访问
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- nginx均衡多tomcat环境配置,及这种环境下的remoteIp及ServerName获取方式
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- 在nginx中配置如何防止直接用ip访问服务器web server及server_name特性讲解
- nginx 转发到 tomcat 的 ServerName 配置问题
- nginx的server_name配置