Home  >  Q&A  >  body text

How to force nginx rewrite to return 200 status code?

               if (!-e $request_filename){
               rewrite "^/maisi/images/(.*)\.jpg" http://img03.taobaocdn.com/.jpg_300x300.jpg last;
               rewrite "^/maisi/images/(.*)\.png" http://img03.taobaocdn.com/.png_300x300.jpg last;
             }

The above is an nginx image rewrite. In fact, my image is a Taobao image!

This will return 302 Moved Temporarily;

Is there a way to return 200 OK

伊谢尔伦伊谢尔伦2712 days ago693

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 17:29:56

    Because rewrite returns 302, the browser will know that it needs to make another request, and then go to Taobao's cdn to get the image. If 200 is returned, all this will not happen

    If you cannot copy the file, you can consider using proxy_pass. In this case, it is equivalent to nginx reading the image from taobao to your server every time, and then your server sends the image to the user, which can return 200 Yes, but the pressure on the server will increase

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:29:56

    location = /example/path {
        return 200;
    }

    reply
    0
  • Cancelreply