第一种:rewrite

server {

  listen                80;

       server_name   www.test.org;

       root                  /temp/test;

       #当访问www.test.org/uri,如果uri资源在项目中不存在,就会重定向到www.test.org/demo/index

       location ~.* {

               if (!-e $request_filename) {

                    rewrite ^ http://www.test.org/demo/index redirect;

               }

       }

}

第二种:反向代理(如果需要重定向到另外一个服务器)

server {

  listen                80;

       server_name   www.test.org;

       root                  /temp/test;

       #当访问www.test.org/uri,如果uri资源在项目中不存在,就会重定向到www.aa.org/demo/index

       location ~.* {

               if (!-e $request_filename) {

                    rewrite ^ /demo/index break;
                    proxy_pass http://www.aa.org;

               }

       }

}

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2021-10-09
  • 2021-10-16
  • 2021-09-28
猜你喜欢
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-10-23
  • 2021-12-19
相关资源
相似解决方案