public:it:nginx

nginx

  • 停止nginx -s stop
  • 重载配置 nginx -s reload
  • location 配置语法:official doc
    location [ = | ~ | ~* | ^~ ] uri { ... }
    location @name { ... }
    • 默认(无标记)是前缀最长匹配;
    • =: 表示精确匹配才执行操作
    • ~: 表示执行正则匹配,且区分大小写
    • ~*: 表示执行正则匹配,但区分大小写
    • ^~: 表示普通字符匹配,前缀匹配有效则配置直接生效,停止向下查找
    • @ 自定义量
    • 匹配优先级官方文档:
      1. Directives with the = prefix that match the query exactly. If found, searching stops.
      2. All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops.
      3. Regular expressions, in order of definition in the configuration file.
      4. If #3 yielded a match, that result is used. Else the match from #2 is used.
    • 中文:
      1. = 的指令严格匹配这个查询。如果找到,停止搜索。
      2. 所有剩下的常规字符串,最长的匹配。如果这个匹配到^〜前缀,搜索停止。
      3. 正则表达式,在配置文件中定义的顺序。
      4. 如果第3条规则产生匹配的话,结果被使用。否则,使用第2条规则的结果。
    • $request_uri代替 $uri
  • nginx 转发直播视频流时一定要关掉代理缓存:proxy_buffering off, 不然会造成视频流的延时!
  • add_header 可以添加响应头字段,但它不会判断原字段是否存在,可能造成重复添加(比如cors头字段重复,浏览器会报错),此时可以考虑使用插件 more_set_headers, 需额外安装模块并让 nginx 加载
  • public/it/nginx.txt
  • 最后更改: 2024/05/27 09:13
  • oakfire