主机头
这个概念来源于windows IIS服务器;我们可以简单理解为,一个主机头就是一个host;
nginx 禁止空主机头配置
可以根据域名和location来分发请求,反向代理;
譬如
server {
listen 80;
server_name _; ##标示空主机头
location / {
root html;
return 404;
}
location ~ /.ht {
deny all;
}
}
这样就禁止空主机头访问;
nginx 设置可以转发的域名
ss
server {
listen 80;
server_name www.test.com;
location / {
root html;
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;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ (favicon.ico) {
root html;
}
}
在本机配置了两个虚拟主机,一个是www.test.com,一个是localhost;
而host绑定为(修改/etc/hosts文件):
127.0.0.1 localhost
127.0.0.1 www.test.com
127.0.0.1 www.test1.com
现在可以通过 localhost和 www.test.com访问,而通过www.test1.com访问则被拒绝,报404错误;