nginx exercises


01
User access www.oldboy.com/test/oldboy.jpg directory anything, in fact, true access is HTTP: // www.oldboy.com www.oldboy.com/test/oldboy.jpg ==> the WWW. oldboy.com/ oldboy.jpg First course: write configuration file server { listen 80; server_name www.jd.com; root /html/www; index index.html; location /test/ { rewrite /test/(.*) http://www.oldboy.com/$1 permanent; } } 02 user access course-. 11 - 22 - 33 .html access is in fact true / Course, / 11 / 22 / 33 / course_33.html #http://www.oldboy.com/course-11-22-33.html ==> http://www.oldboy.com/course/11/22/33/course_33.html server { listen 80; root /html/www; server_name www.oldboy.com; index index.html; location / { rewrite (.*)-(.*)-(.*)-(.*)\.(.*) $1/$2/$3/$4/course_$4.$5 last; #灵活rewrite ^/course-(.*)-(.*)-(.*).html$ /course/$1/$2/$3/course_$3.html redirect; #固定rewrite ^/course-(.*) /course/11/22/33/course_33.html redirect; } } 03 User access www.jd.com jump into www.oldboy.com (difficulty) - Infinite Jump method one: server { listen 80; server_name www.jd.com; rewrite ^/(.*) http://www.oldboy.com/$1 permanent; } server { listen 80; server_name www.oldboy.com; root /html/www; index index.html; } Method Two: server { listen 80; server_name www.oldboy.com www.jd.com; root /html/www; index index.html; location / { if ($http_host ~* ^www.jd.com$) { rewrite ^/(.*) http://www.oldboy.com/$1 permanent; } } } curl -v --- show detailed access process curl -L --- track jump process, display page information

 

Guess you like

Origin www.cnblogs.com/zhanghongqi/p/11832769.html