URL rewrite of Cento7+nginx
Our previous article wrote a Cento7+nginx reverse proxy implementation of multi-domain jump, today mainly introduce the Cento7+nginx URL rewrite,
Hostname:a-s.ixmsoft.com
ip:192.168.5.20
Role:nginx Server
We're going to install the Nginx warehouse first.
Yum Install Http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmyum Install Nginx
650) this.width=650; "title=" clip_image001 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image001 "src=" Http://s3.51cto.com/wyfs02/M00/8B/5F/wKioL1hLm1KjymgwAAEmP8GMnEA565.png "height=" 414 "/>
After the installation, we look at the default Nginx configuration file
Vim/etc/nginx/nginx.conf
The default nginx.conf file
User nginx;worker_processes 1;error_log/var/log/nginx/error.log warn;pid/var/run/nginx.pid;events {worker_ Connections 1024;} HTTP {include/etc/nginx/mime.types;default_type Application/octet-stream;log_format main ' $remote _addr-$remote _ User [$time _local] "$request" "$status $body _bytes_sent" $http _referer "" "$http _user_agent" "$http _x_forwarded_for" '; Access_log/var/log/nginx/access.log main;sendfile on; #tcp_nopush on;keepalive_timeout; #gzip on;include/etc/ nginx/conf.d/*.conf;
650) this.width=650; "title=" clip_image001[4] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[4] "src=" http://s3.51cto.com/wyfs02/M00/8B/62/wKiom1hLm1PwDoNxAACyshI-D-I202.png "height=" 341 "/>
We see the Nginx default configuration includes an option to include multiple profiles, so we can generally not modify this default configuration file
650) this.width=650; "title=" clip_image001[6] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[6] "src=" http://s3.51cto.com/wyfs02/M01/8B/62/wKiom1hLm1SioqBXAADP-SNwA-I603.png "height=" 370 "/>
We view the default configuration file
650) this.width=650; "title=" clip_image001[8] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[8] "src=" http://s3.51cto.com/wyfs02/M01/8B/5F/wKioL1hLm1Sj5vSoAABBqdYHQyk031.png "height="/>
We view the default default.conf file contents
650) this.width=650; "title=" clip_image001[10] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[10] "src=" http://s3.51cto.com/wyfs02/M02/8B/62/wKiom1hLm1XwndbiAAFSi9CNzwg502.png "height=" 455 "/>
We see that this configuration file has taken up 80 ports and we will modify the 80 port.
650) this.width=650; "title=" clip_image001[12] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[12] "src=" http://s3.51cto.com/wyfs02/M00/8B/62/wKiom1hLm1bizUTBAADykMVMOA0953.png "height=" 378 "/>
Next we create a new configuration file, or you can modify it in the default configuration file. But not recommended
Cd/etc/nginx/conf.d/vim Rewrite.confserver {Listen 80;server_name ixmsoft.com;location/{rewrite ^/(. *)/http:/ www.baidu.com;} Access_log Logs/rewrite_access.log;}
650) this.width=650; "title=" clip_image001[14] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[14] "src=" Http://s3.51cto.com/wyfs02/M02/8B/5F/wKioL1hLm1biLYqeAABmI7-JB_U397.png "height=" 186 "/>
After saving the exit, we restart Nginx
Systemctl Stop Nginxsystemctl start Nginx
We need to point the server_name domain name to the Nginx IP locally before it can be accessed.
Add records in DNS, d1.ixmsoft.com point to Nginx IP 192.168.5.20
650) this.width=650; "title=" clip_image001[16] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[16] "src=" http://s3.51cto.com/wyfs02/M00/8B/62/wKiom1hLm1eBMHVUAABNjd1-UZg975.png "height="/>
Then test access
650) this.width=650; "title=" clip_image001[18] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[18] "src=" Http://s3.51cto.com/wyfs02/M02/8B/62/wKiom1hLm1fyxvXwAABYDUiH1cM669.png "height=" 276 "/>
Then we look at log,
Cat/etc/nginx/logs/rewrite_access.log
650) this.width=650; "title=" clip_image001[20] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[20] "src=" http://s3.51cto.com/wyfs02/M00/8B/5F/wKioL1hLm1iBYBXkAAA6JtHTehI434.png "height="/>
Of course, we can also add more than one server to achieve the domain name jump, in the original configuration file added can
server {Listen 80;server_name d1.ixmsoft.com;location/{rewrite ^/(. *) http://www.baidu.com;} Access_log Logs/rewrite_access.log;} server {Listen 80;server_name d2.ixmsoft.com;location/{rewrite ^/(. *) http://www.sina.com;} Access_log Logs/rewrite_access02.log;}
650) this.width=650; "title=" clip_image001[22] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[22] "src=" http://s3.51cto.com/wyfs02/M01/8B/62/wKiom1hLm3OA1MTiAADHq7CNIwc920.png "height=" 305 "/>
After rebooting, we test the access
650) this.width=650; "title=" clip_image001[24] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[24] "src=" http://s3.51cto.com/wyfs02/M01/8B/5F/wKioL1hLm3SxlhFPAAFC-ktpIJk619.png "height=" 334 "/>
Also view Log
650) this.width=650; "title=" clip_image001[26] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ IMAGE001[26] "src=" http://s3.51cto.com/wyfs02/M02/8B/62/wKiom1hLm3XiIMAsAAByqPiUB-o124.png "height="/>
This article from "Gao Wenrong" blog, declined reprint!
URL rewrite of Cento7+nginx