1.别名:在配置文件里server段加入wolf.com即可实现
2.重写(rewrite)
第一种方法地址栏不变,第二种方法地址栏会跳转变化。
1.配置文件加入wolf.com
[root@nginx conf]# vi nginx.conf
\
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.wolf.com wolf.com; (这里加入wolf.com)
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 80;
server_name bbs.wolf.com;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 80;
server_name blog.wolf.com;
location / {
root html/blog;
index index.html index.htm;
}
}
客户端测试加入host表
2.重写301跳转
rewrite ^/(.*) http://www.wolf.com/$1 permanent;
[root@nginx conf]# cat nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name wolf.com;
location / {
root html/www;
index index.html index.htm;
rewrite ^/(.*) http://www.wolf.com/$1 permanent;
}
}
server {
listen 80;
server_name www.wolf.com;
location / {
root html/www;
index index.html index.htm;
}
}
server {
listen 80;
server_name bbs.wolf.com;
location / {
root html/bbs;
index index.html index.htm;
}
}
server {
listen 80;
server_name blog.wolf.com;
location / {
root html/blog;
index index.html index.htm;
}
}
##status
server {
listen 80;
server_name status.wolf.com;
location / {
stub_status on;
access_log off;
}
}
}
再输入wolf.com,自动跳转到www.wolf.com
现在输入192.168.3.49,自动跳转到www.wolf.com
如果没有跳转段
server {
listen 80;
server_name wolf.com;
location / {
root html/www;
index index.html index.htm;
rewrite ^/(.*) http://www.wolf.com/$1 permanent;
}
}
使用ip访问默认为第一个server
3.防止恶意绑定域名
加入下面这段
server {
listen 80;
location / {
deny all;
}
}
nginx: the configuration file /data/nginx1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx1.8.1/conf/nginx.conf test is successful
[root@nginx conf]# ../sbin/nginx -s reload
测试curl或者ie访问都会报403错误
[root@nginx conf]# curl -I http://192.168.3.49/
HTTP/1.1 403 Forbidden
Server: nginx/1.8.1
Date: Wed, 16 Nov 2016 05:49:12 GMT
Content-Type: text/html
Content-Length: 168
Connection: keep-alive
hosts表里添加记录(恶意解析)
192.168.3.49 www.sex.com
在本地ie打开网页
会发现跳转到403界面
动力节点在线课程涵盖零基础入门,高级进阶,在职提升三大主力内容,覆盖Java从入门到就业提升的全体系学习内容。全部Java视频教程免费观看,相关学习资料免费下载!对于火爆技术,每周一定时更新!如果想了解更多相关技术,可以到动力节点在线免费观看Nginx服务器视频教程学习哦!
代码小兵86504-19 19:55
代码小兵49806-21 15:40
代码小兵69607-21 11:32
代码小兵87207-21 12:51