开发者

nginx how to include rewrite outside of root

How do you call get a file that outside of the root to the be processed. i was reading about the alias and couldnt get it working. so ive tried adding a new root within the location no luck.

this is a cutdown of my config file

server {
  listen  443;
  server_name   dom开发者_运维问答ain.com;

  --- 

  root ../var/www/domain/public_html;


   # works as being called form within the root
   location /login {
   rewrite ^/login /account/login permanent;
    }

#need to

  location /validation/code.png {

    root /var/www/domain/include;

  rewrite ^/validation/code.png /captcha/display_captcha.php;
  }

}


You are rewriting the png file to a php file. This will create a sub request for /captcha/display_captcha.php. Is there a location for php in your config? Assuming the php location uses the general root, when the sub request hits this, /captcha/display_captcha.php will not be found an you will get a 404 error.

Your best bet is to copy the php location and create a php location specifically for the php file.

server {
    listen  443;
    server_name   domain.com;
    root /var/www/domain/public_html;

    ...

    location = /validation/code.png {
        rewrite ^/validation/code.png /captcha/display_captcha.php;
    }
    location ~ ^/captcha/display_captcha.php {
        root /var/www/domain/include
        ...
        # copy php processing code from normal php location.
    }
}

Better still, just use '/captcha/display_captcha.php' directly in your html and drop '/validation/code.png' altogether.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜