相关推荐:ruby on rails - Play for Scala: Scala object as DAO

when I want to make a query to the model (for example, to get all the users in the database) I do something like User::all().I'm new to Play for Scala and Slick, and all the projects and documentation I've already seen

1. 为什么要关闭X-Forwarded-For解析?

某些用户可能会使用透明代理访问你的网站,透明代理在转发请求的时候会通过X-Forwarded-For请求头带上真实的请求IP地址,默认情况下,Play会解析这个请求头并赋值给request.remoteAddress,进而导致在Action中通过request.remoteAddress获取到的IP地址是一个内网地址,例如192.168.1.2。这些内网地址对地域统计来说没有任何意义,所以索性就关闭X-Forwarded-For解析,直接获取代理服务器地址。

2. 如何关闭X-Forwarded-For解析?

很简单,只需要在application.conf配置文件中增加一行配置即可关闭所有X-Forwarded-For解析.

play.http.forwarded.trustedProxies = []

3.

如何启用X-Forwarded-For解析?

1) 仅信任本地的反向代理服务器

play.http.forwarded.trustedProxies=["::1", "127.0.0.1"]

2) 信任特定的代理服务器

play.http.forwarded.trustedProxies=["192.168.0.0/24", "::1", "127.0.0.1"]

192.168.0.0/24表示整个C类地址段,即192.168.0.0-192.168.0.255。

3) 信任所有的代理服务器

play.http.forwarded.trustedProxies=["0.0.0.0/0", "::/0"]

4. 参考

Setting up a front end HTTP server

相关推荐:playframework - How to check if request is for static content in play framework in scala

nt(js, css) to enable caching... How can I get it from the request object in play Thanks scala playframework cache-control share|improve this question

快照源:http://my.oschina.net/joymufeng/blog/670985