一、配置地址重写
1、 创建访问目录和测试页
1)
创建目录和测试页
[[email protected] ~]# mkdir /code
[[email protected] ~]# mkdir /code/zh
[[email protected] ~]# mkdir /code/en
[[email protected] ~]# echo “zh” > /code/zh/index.html
[[email protected] ~]# echo “en” > /code/en/index.html
[[email protected] ~]# echo “wwwwww” > /code/index.html
2)
配置地址重写
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.benet.com;
location / {
root /code/;
index index.html;
}
}
server {
listen 192.168.100.10:80;
server_name www.benet.com.zh www.benet.com.en;
location / {
if ( $http_host ~* “zh”) {
set http://www.benet.com/$language redirect;
}
if ( $http_host ~* “en”) {
set http://www.benet.com/$language redirect;
}
}
}
3)
杀死nginx并查看和启动查看
[[email protected] ~]# killall nginx
[[email protected] ~]# nginx -t
[[email protected] ~]# nginx
[[email protected] ~]# netstat -anptu | grep 80
2、 配置DNS
1)
配置dns
[[email protected] ~]# vim /etc/named.conf
options {
listen-on port 53 { any; };
directory “/var/named”;
};
zone “benet.com” IN {
type master;
file “benet.com.zone”;
};
zone “benet.com.zh” IN {
type master;
file “benet.com.zh.zone”;
};
zone “benet.com.en” IN {
type master;
file “benet.com.en.zone”;
[[email protected] ~]# vim /var/named/benet.com.zone
$TTL 86400
@ SOA benet.com. root.benet.com (
2020031210
1H
15M
1W
1D
)
@ NS centos01.benet.com.
centos01 A 192.168.100.10
www A 192.168.100.10
[[email protected] ~]# vim /var/named/benet.com.zh.zone
$TTL 86400
@ SOA benet.com.zh. root.benet.com.zh (
2020031210
1H
15M
1W
1D
)
@ NS centos01.benet.com.zh.
centos01 A 192.168.100.10
www A 192.168.100.10
[[email protected] ~]# vim /var/named/benet.com.en.zone
$TTL 86400
@ SOA benet.com.en. root.benet.com.en (
2020031210
1H
15M
1W
1D
)
@ NS centos01.benet.com.en.
centos01 A 192.168.100.10
www A 192.168.100.10
2)
重新启动
[[email protected] ~]# systemctl restart named
3、 客户端访问
1)
客户端配置IP地址
2)
客户端访问
*二、 配置基于域名地址跳转
1)
基于域名地址跳转**
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.benet.com;
location / {
root /code/;
index index.html;
}
}
server {
listen 192.168.100.10:80;
server_name bbs.benet.com;
location / {
if (KaTeX parse error: Expected '}', got 'EOF' at end of input: … rewrite ^/(.*) http://www.benet.com/$1 permanent;
}
}
}
2)
查看是否错误,重新启动ngixn
[[email protected] ~]# nginx -t
[[email protected] ~]# killall nginx
[[email protected] ~]# nginx
3)
配置dns并重新启动
[[email protected] ~]# vim /etc/named.conf
options {
listen-on port 53 { any; };
directory “/var/named”;
};
zone “benet.com” IN {
type master;
file “benet.com.zone”;
};
zone “bbs.com” IN {
type master;
file “bbs.com.zone”;
};
[[email protected] ~]# cp /var/named/benet.com.zone /var/named/bbs.com.zone
[[email protected] ~]# vim /var/named/bbs.com.zone
[[email protected] ~]# vim /var/named/bbs.com.zone
$TTL 86400
@ SOA bbs.com. root.bbs.com (
2020031210
1H
15M
1W
1D
)
@ NS centos01.bbs.com.
centos01 A 192.168.100.10
www A 192.168.100.10
[[email protected] ~]# systemctl restart named
4)
客户端访问
**三、 配置客户端带参数跳转
1)
客户端带参数跳转**
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.100.10:80;
server_name www.benet.com;
location / {
root /code/;
index index.html;
}
}
server {
listen 192.168.100.10:80;
server_name bbs.benet.com;
location / {
if ( ) {
rewrite (.*) http://www.benet.com permanent;
}
}
}
2)
检查nginx是否配置错误并重启
[[email protected] ~]# nginx -t
[[email protected] ~]# killall nginx
[[email protected] ~]# nginx
3)
创建一个带符号的测试页
[[email protected] ~]# vim /code/100-200-100.html
1111111111!!!
4)
客户端访问