====== nginx ====== * 停止''nginx -s stop'' * 重载配置 ''nginx -s reload'' ===== Articles ===== * [[http://tengine.taobao.org/book/index.html|Nginx开发从入门到精通-淘宝]] ===== 配置语法 ===== * [[http://nginx.org/en/docs/|official docs]] * location 配置语法:[[http://nginx.org/en/docs/http/ngx_http_core_module.html#location|official doc]]location [ = | ~ | ~* | ^~ ] uri { ... } location @name { ... } * 默认(无标记)是前缀最长匹配; * ''='': 表示精确匹配才执行操作 * ''~'': 表示执行正则匹配,且区分大小写 * ''~*'': 表示执行正则匹配,但**不**区分大小写 * ''^~'': 表示普通字符匹配,前缀匹配有效则配置直接生效,停止向下查找 * ''@'' 自定义量 * 匹配优先级官方文档: - Directives with the = prefix that match the query exactly. If found, searching stops. - All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops. - Regular expressions, in order of definition in the configuration file. - If #3 yielded a match, that result is used. Else the match from #2 is used. * 中文: - ''='' 的指令严格匹配这个查询。如果找到,停止搜索。 - 所有剩下的常规字符串,最长的匹配。如果这个匹配到^〜前缀,搜索停止。 - 正则表达式,在配置文件中定义的顺序。 - 如果第3条规则产生匹配的话,结果被使用。否则,使用第2条规则的结果。 ==== 去除 server header 版本号 ==== * 在 ''/etc/nginx/nginx.conf'' 里 http 下 添加 ''server_tokens off''; * 修改 ''/etc/nginx/fastcgi_param'' 与 ''/etc/nginx/fastcgi.conf'' 下的对应条''SERVER_SOFTWARE''; * 或者修改源码,或者用插件 :[[http://stackoverflow.com/questions/246227/how-do-you-change-the-server-header-returned-by-nginx]] ==== 添加基本认证 ==== * [[https://www.nginx.com/resources/admin-guide/restricting-access-auth-basic/|Restricting access auth basic]] * [[http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html|ngx_http_auth_basic_module]] ==== Tips ==== * [[https://github.com/vulhub/vulhub/tree/master/nginx/insecure-configuration|Nginx 配置错误导致漏洞]] * 用 ''$request_uri''代替 ''$uri'' * [[https://github.com/yandex/gixy|检测nginx配置是否有安全问题的工具: gixy]] * nginx 转发直播视频流时一定要关掉代理缓存:''proxy_buffering off'', 不然会造成视频流的延时!