Nginx Rewrit(实验)

Nginx Rewrite

  • 基于域名跳转
  • 基于IP进行过滤
  • 基于旧、新域名跳转并加目录
  • 基于参数匹配的跳转
  • 基于目录下所有php文件跳转
  • 基于最普通url请求的跳转

-------------------------------------------------nginx rewrite------------------------------------------

基于域名跳转

[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# yum install bind -y
[root@localhost ~]# vim /etc/named.conf 

Nginx Rewrit(实验)_第1张图片

[root@localhost ~]# vim /etc/named.rfc1912.zones 

Nginx Rewrit(实验)_第2张图片

[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# vim kgc.com.zone 

Nginx Rewrit(实验)_第3张图片

[root@localhost named]# cp -p kgc.com.zone newkgc.com.zone
[root@localhost named]# systemctl start named
[root@localhost named]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第4张图片

[root@localhost named]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
[root@localhost named]# systemctl start nginx

Nginx Rewrit(实验)_第5张图片

基于IP进行过滤

[root@localhost named]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第6张图片

[root@localhost named]# cd /usr/share/nginx/html/
[root@localhost html]# vim error.html

Nginx Rewrit(实验)_第7张图片

[root@localhost html]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost html]# systemctl restart nginx

Nginx Rewrit(实验)_第8张图片
Nginx Rewrit(实验)_第9张图片
Nginx Rewrit(实验)_第10张图片
Nginx Rewrit(实验)_第11张图片

基于旧、新域名跳转并加目录

[root@localhost html]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第12张图片

[root@localhost html]# vim /var/named/kgc.com.zone 

Nginx Rewrit(实验)_第13张图片
在这里插入图片描述
Nginx Rewrit(实验)_第14张图片

基于参数匹配的跳转

[root@localhost named]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第15张图片

[root@localhost named]# systemctl restart nginx

Nginx Rewrit(实验)_第16张图片
Nginx Rewrit(实验)_第17张图片

基于目录下所有php文件跳转

[root@localhost named]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第18张图片

[root@localhost named]# systemctl restart nginx

Nginx Rewrit(实验)_第19张图片
Nginx Rewrit(实验)_第20张图片

基于最普通url请求的跳转

[root@localhost named]# vim /etc/nginx/conf.d/default.conf 

Nginx Rewrit(实验)_第21张图片

[root@localhost named]# systemctl restart nginx

Nginx Rewrit(实验)_第22张图片

Nginx Rewrit(实验)_第23张图片

你可能感兴趣的:(Nginx)