1.当访问的文件和目录不存在时,重定向到某个html文件 if( !-e $request_filename ) { rewrite ^/(.*)$ index.html last;
}
或者:
#当URL符合^\/(api)规则时,跳转到http://127.0.0.1:9178,即在upstream中配置的那个值
location / { #默认跳转到http://127.0.0.1:9000 proxy_pass http://127.0.0.1:9000; }
location ~ ^\/(api){
proxy_pass http://api;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 100m;
}如对图片实现找不图片请求其他服务器:location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_set_header Host apph.zhidekan.me; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; if (!-e $request_filename) { #proxy_cache_key $host$uri$is_args$args; proxy_pass http://apph; #proxy_pass_header Set-Cookie; } expires 30d; }其中:upstream.confupstream apph{ ip_hash; server 10.13.40.48:80 max_fails=2 fail_timeout=60s; #server 127.0.0.1:80 max_fails=2 fail_timeout=60s; }