1.rewrite配置
- server {
- listen 80 default_server;
- server_name jeson.t.imooc.io;
-
- access_log /var/log/nginx/log/host.access.log main;
-
- root /opt/app/code;
- location ~ ^/break {
- rewrite ^/break /test/ break;
- }
-
- location ~ ^/last {
- rewrite ^/last /test/ last;
- }
-
- location ~ ^/imooc {
- rewrite ^/imooc http://www.imooc.com/ permanent;
-
- }
- location / {
- rewrite ^/course-(\d+)-(\d+)-(\d+)\.html$ /course/$1/$2/course_$3.html break;
- if ($http_user_agent ~* Chrome) {
- rewrite ^/nginx http://coding.imooc.com/class/121.html redirect;
- }
-
- if (!-f $request_filename) {
- rewrite ^/(.*)$ http://www.baidu.com/$1 redirect;
- }
- index index.html index.htm;
- }
-
- location /test/ {
- default_type application/json;
- return 200 '{"status":"success"}';
- }
- }
-
2.rewrite优先级