Packt.Nginx.HTTP.Server.3rd.Edition
By admin
nginx location匹配优先级
-
location blocks with the = modifier: If the specified string exactly matches
the requested URI, Nginx retains the location block.
匹配使用=的严格相等的路径
-
location blocks with no modifier: If the specified string exactly matches the
requested URI, Nginx retains the location block.
匹配严格相等的无匹配符号的路径,例如 location /abc {…},请求正好为/abc
-
location blocks with the ^~ modifier: If the specified string matches the
beginning of the requested URI, Nginx retains the location block.
匹配以路径开头的请求
-
location blocks with ~ or ~* modifier: If the regular expression matches the
requested URI, Nginx retains the location block.
匹配包含的路径,*为不区分大小写规则
-
location blocks with no modifier: If the specified string matches the
beginning of the requested URI, Nginx retains the location block.
匹配无匹配符号的路径,例如 location /api {…}
功能模块
- nginx ssi可以当服务端渲染
- 可以连memcache
- 可以裁剪或旋转等处理图片
- 可以连Email服务
- 可以修改,替换代理内容
- 可以操作xslt
- stub_status 监控nginx简单状态
- WebDAV协议扩展
其他
-
后面有几章都是apache到nginx的迁移,铁了心要挖apache墙脚
-
后端负载均衡主题
在upstream中可以用has $cookie_username将cookie中同一个username值的请求都使用同一个后端连接
stream module可以代理tcp请求,写法和代理http的upstream一模一样
常用语法注意点:
-
Having try_files and the if statements in the same location block is not
recommended as the try_files directive will, in most cases, be ignored.
try_files与if尽量不要在一个location中使用,大多数情况下try_files会失效。
-
Some directives are theoretically allowed within the if block, but can create
serious issues—for instance, proxy_pass and fastcgi_pass . You should
keep those within the location blocks.
理论上一些指令可以放到if里,但会引起一些严重的问题,比如proxy_pass与fastcgi_pass,应放到location中。
-
You should avoid using the if blocks within a location block that captures
regular expression patterns from within its modifier.
避免在使用正则的location中使用if
-
总结:能不用if就不用if
-
最后本书推荐精通指南 Mastering Nginx by Dimitri Aivaliotis, and
NGINX High Performance, by Rahul Sharma,Nginx
modules: Nginx Module Extension (by Usama Dar)
-