<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Damian Lau</title>
    <description>Damian&apos;s home page on the World Wide Web.</description>
    <link>https://yanl.cc</link>
    <atom:link href="https://yanl.cc/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Nginx文档【持续更新】</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#简介&quot; id=&quot;markdown-toc-简介&quot;&gt;简介&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#how-to&quot; id=&quot;markdown-toc-how-to&quot;&gt;How-To&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#开发&quot; id=&quot;markdown-toc-开发&quot;&gt;开发&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#模块参考&quot; id=&quot;markdown-toc-模块参考&quot;&gt;模块参考&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;简介&quot;&gt;简介&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;安装Nginx&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/ngx-docs/building-nginx-from-sources&quot;&gt;源码编译Nginx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;新手指南&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.nginx.com/nginx/admin-guide/&quot;&gt;管理员指南&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;控制Nginx&lt;/li&gt;
  &lt;li&gt;连接处理方法&lt;/li&gt;
  &lt;li&gt;设置hash&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/ngx-docs/debugging-log&quot;&gt;调试日志&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;打印日志到syslog&lt;/li&gt;
  &lt;li&gt;配置文件中的计量单位&lt;/li&gt;
  &lt;li&gt;命令行参数&lt;/li&gt;
  &lt;li&gt;Nginx for Windows&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;支持QUIC和HTTP/3&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/ngx-docs/how-nginx-processes-a-request&quot;&gt;Nginx 是如何处理一个请求的&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/ngx-docs/server-names&quot;&gt;虚拟主机名 Server names&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;使用Nginx作为HTTP负载均衡器&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://nginx.org/cn/docs/http/configuring_https_servers.html&quot;&gt;配置HTTPS 服务&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Nginx 是如何处理TCP/UDP会话的&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;njs 脚本&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;《The Architecture of Open Source Applications》中的nginx章节&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-to&quot;&gt;How-To&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;使用VC在Win32平台下编译Nginx&lt;/li&gt;
  &lt;li&gt;在Amazon EC2上配置Nginx Plus环境&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;使用DTrace调试Nginx&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/ngx-docs/converting-rewrite-rules&quot;&gt;转换重写规则&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WebSocket 代理&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;开发&quot;&gt;开发&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;贡献变更&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;a href=&quot;/ngx-docs/ngx-devel-guide&quot;&gt;开发者指南&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;模块参考&quot;&gt;模块参考&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;指令列表&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;变量列表&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;核心功能&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_http_core_module&lt;/li&gt;
  &lt;li&gt;ngx_http_access_module&lt;/li&gt;
  &lt;li&gt;ngx_http_addition_module&lt;/li&gt;
  &lt;li&gt;ngx_http_api_module&lt;/li&gt;
  &lt;li&gt;ngx_http_auth_basic_module&lt;/li&gt;
  &lt;li&gt;ngx_http_auth_jwt_module&lt;/li&gt;
  &lt;li&gt;ngx_http_auth_request_module&lt;/li&gt;
  &lt;li&gt;ngx_http_autoindex_module&lt;/li&gt;
  &lt;li&gt;ngx_http_browser_module&lt;/li&gt;
  &lt;li&gt;ngx_http_charset_module&lt;/li&gt;
  &lt;li&gt;ngx_http_dav_module&lt;/li&gt;
  &lt;li&gt;ngx_http_empty_gif_module&lt;/li&gt;
  &lt;li&gt;ngx_http_f4f_module&lt;/li&gt;
  &lt;li&gt;ngx_http_fastcgi_module&lt;/li&gt;
  &lt;li&gt;ngx_http_flv_module&lt;/li&gt;
  &lt;li&gt;ngx_http_geo_module&lt;/li&gt;
  &lt;li&gt;ngx_http_geoip_module&lt;/li&gt;
  &lt;li&gt;ngx_http_gunzip_module&lt;/li&gt;
  &lt;li&gt;ngx_http_gzip_module&lt;/li&gt;
  &lt;li&gt;ngx_http_gzip_static_module&lt;/li&gt;
  &lt;li&gt;ngx_http_headers_module&lt;/li&gt;
  &lt;li&gt;ngx_http_hls_module&lt;/li&gt;
  &lt;li&gt;ngx_http_image_filter_module&lt;/li&gt;
  &lt;li&gt;ngx_http_index_module&lt;/li&gt;
  &lt;li&gt;ngx_http_js_module&lt;/li&gt;
  &lt;li&gt;ngx_http_keyval_module&lt;/li&gt;
  &lt;li&gt;ngx_http_limit_conn_module&lt;/li&gt;
  &lt;li&gt;ngx_http_limit_req_module&lt;/li&gt;
  &lt;li&gt;ngx_http_log_module&lt;/li&gt;
  &lt;li&gt;ngx_http_map_module&lt;/li&gt;
  &lt;li&gt;ngx_http_memcached_module&lt;/li&gt;
  &lt;li&gt;ngx_http_mirror_module&lt;/li&gt;
  &lt;li&gt;ngx_http_mp4_module&lt;/li&gt;
  &lt;li&gt;ngx_http_perl_module&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_proxy_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;ngx_http_random_index_module&lt;/li&gt;
  &lt;li&gt;ngx_http_realip_module&lt;/li&gt;
  &lt;li&gt;ngx_http_referer_module&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_rewrite_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;ngx_http_scgi_module&lt;/li&gt;
  &lt;li&gt;ngx_http_secure_link_module&lt;/li&gt;
  &lt;li&gt;ngx_http_session_log_module&lt;/li&gt;
  &lt;li&gt;ngx_http_spdy_module&lt;/li&gt;
  &lt;li&gt;ngx_http_split_clients_module&lt;/li&gt;
  &lt;li&gt;ngx_http_ssi_module&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_ssl_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;ngx_http_status_module&lt;/li&gt;
  &lt;li&gt;ngx_http_stub_status_module&lt;/li&gt;
  &lt;li&gt;ngx_http_sub_module&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_upstream_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;ngx_http_upstream_conf_module&lt;/li&gt;
  &lt;li&gt;ngx_http_upstream_hc_module&lt;/li&gt;
  &lt;li&gt;ngx_http_userid_module&lt;/li&gt;
  &lt;li&gt;ngx_http_uwsgi_module&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_v2_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;ngx_http_v3_module&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ngx_http_xslt_module&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_mail_core_module&lt;/li&gt;
  &lt;li&gt;ngx_mail_auth_http_module&lt;/li&gt;
  &lt;li&gt;ngx_mail_proxy_module&lt;/li&gt;
  &lt;li&gt;ngx_mail_ssl_module&lt;/li&gt;
  &lt;li&gt;ngx_mail_imap_module&lt;/li&gt;
  &lt;li&gt;ngx_mail_pop3_module&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ngx_mail_smtp_module&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_stream_core_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_access_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_geo_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_geoip_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_js_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_keyval_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_limit_conn_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_log_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_map_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_proxy_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_realip_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_return_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_split_clients_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_ssl_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_ssl_preread_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_upstream_module&lt;/li&gt;
  &lt;li&gt;ngx_stream_upstream_hc_module&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ngx_stream_zone_sync_module&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_google_perftools_module&lt;/li&gt;
  &lt;li&gt;ngx_otel_module&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://nginx.org/en/docs/&quot;&gt;reference&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;updated at 2023.08.21&lt;/em&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 21 Aug 2023 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/nginx/2023/08/21/nginx-document/</link>
        <guid isPermaLink="true">https://yanl.cc/nginx/2023/08/21/nginx-document/</guid>
      </item>
    
      <item>
        <title>Nginx开发指南</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#简介&quot; id=&quot;markdown-toc-简介&quot;&gt;简介&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#代码目录结构&quot; id=&quot;markdown-toc-代码目录结构&quot;&gt;代码目录结构&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#头文件&quot; id=&quot;markdown-toc-头文件&quot;&gt;头文件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#整数类型&quot; id=&quot;markdown-toc-整数类型&quot;&gt;整数类型&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#通用返回值&quot; id=&quot;markdown-toc-通用返回值&quot;&gt;通用返回值&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#错误处理&quot; id=&quot;markdown-toc-错误处理&quot;&gt;错误处理&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#字符串-string&quot; id=&quot;markdown-toc-字符串-string&quot;&gt;字符串 String&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#简介-1&quot; id=&quot;markdown-toc-简介-1&quot;&gt;简介&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#字符串格式化&quot; id=&quot;markdown-toc-字符串格式化&quot;&gt;字符串格式化&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#数字转换&quot; id=&quot;markdown-toc-数字转换&quot;&gt;数字转换&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#正则表达式&quot; id=&quot;markdown-toc-正则表达式&quot;&gt;正则表达式&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#时间&quot; id=&quot;markdown-toc-时间&quot;&gt;时间&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#容器类型&quot; id=&quot;markdown-toc-容器类型&quot;&gt;容器类型&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#数组-array&quot; id=&quot;markdown-toc-数组-array&quot;&gt;数组 Array&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#链表-list&quot; id=&quot;markdown-toc-链表-list&quot;&gt;链表 List&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#双向链表-queue&quot; id=&quot;markdown-toc-双向链表-queue&quot;&gt;双向链表 Queue&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#红黑树-rb-tree&quot; id=&quot;markdown-toc-红黑树-rb-tree&quot;&gt;红黑树 RB-Tree&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#哈希表-hash&quot; id=&quot;markdown-toc-哈希表-hash&quot;&gt;哈希表 Hash&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#通配符匹配&quot; id=&quot;markdown-toc-通配符匹配&quot;&gt;通配符匹配&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#内存管理&quot; id=&quot;markdown-toc-内存管理&quot;&gt;内存管理&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#堆栈-heap&quot; id=&quot;markdown-toc-堆栈-heap&quot;&gt;堆栈 Heap&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#池-pool&quot; id=&quot;markdown-toc-池-pool&quot;&gt;池 Pool&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#共享内存&quot; id=&quot;markdown-toc-共享内存&quot;&gt;共享内存&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#日志&quot; id=&quot;markdown-toc-日志&quot;&gt;日志&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#生命周期-cycle&quot; id=&quot;markdown-toc-生命周期-cycle&quot;&gt;生命周期 Cycle&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#缓冲区-buffer&quot; id=&quot;markdown-toc-缓冲区-buffer&quot;&gt;缓冲区 Buffer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#网络&quot; id=&quot;markdown-toc-网络&quot;&gt;网络&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#链接-connection&quot; id=&quot;markdown-toc-链接-connection&quot;&gt;链接 Connection&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#事件驱动&quot; id=&quot;markdown-toc-事件驱动&quot;&gt;事件驱动&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#事件&quot; id=&quot;markdown-toc-事件&quot;&gt;事件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#io-事件&quot; id=&quot;markdown-toc-io-事件&quot;&gt;I/O 事件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#定时器事件&quot; id=&quot;markdown-toc-定时器事件&quot;&gt;定时器事件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#后处理事件&quot; id=&quot;markdown-toc-后处理事件&quot;&gt;后处理事件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#事件循环&quot; id=&quot;markdown-toc-事件循环&quot;&gt;事件循环&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#进程&quot; id=&quot;markdown-toc-进程&quot;&gt;进程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#线程&quot; id=&quot;markdown-toc-线程&quot;&gt;线程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#模块&quot; id=&quot;markdown-toc-模块&quot;&gt;模块&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#添加新模块&quot; id=&quot;markdown-toc-添加新模块&quot;&gt;添加新模块&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#核心模块&quot; id=&quot;markdown-toc-核心模块&quot;&gt;核心模块&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#配置指令&quot; id=&quot;markdown-toc-配置指令&quot;&gt;配置指令&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#http&quot; id=&quot;markdown-toc-http&quot;&gt;HTTP&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#链接-connction&quot; id=&quot;markdown-toc-链接-connction&quot;&gt;链接 Connction&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#请求-request&quot; id=&quot;markdown-toc-请求-request&quot;&gt;请求 Request&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#配置&quot; id=&quot;markdown-toc-配置&quot;&gt;配置&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#处理阶段&quot; id=&quot;markdown-toc-处理阶段&quot;&gt;处理阶段&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#变量&quot; id=&quot;markdown-toc-变量&quot;&gt;变量&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#访问已存在的变量&quot; id=&quot;markdown-toc-访问已存在的变量&quot;&gt;访问已存在的变量&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#创建新变量&quot; id=&quot;markdown-toc-创建新变量&quot;&gt;创建新变量&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#复杂值&quot; id=&quot;markdown-toc-复杂值&quot;&gt;复杂值&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#请求重定向&quot; id=&quot;markdown-toc-请求重定向&quot;&gt;请求重定向&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#子请求&quot; id=&quot;markdown-toc-子请求&quot;&gt;子请求&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#终止请求&quot; id=&quot;markdown-toc-终止请求&quot;&gt;终止请求&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#请求体&quot; id=&quot;markdown-toc-请求体&quot;&gt;请求体&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#响应&quot; id=&quot;markdown-toc-响应&quot;&gt;响应&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#响应头&quot; id=&quot;markdown-toc-响应头&quot;&gt;响应头&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#响应头过滤处理&quot; id=&quot;markdown-toc-响应头过滤处理&quot;&gt;响应头过滤处理&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#响应体&quot; id=&quot;markdown-toc-响应体&quot;&gt;响应体&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#响应体过滤处理&quot; id=&quot;markdown-toc-响应体过滤处理&quot;&gt;响应体过滤处理&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#创建过滤模块&quot; id=&quot;markdown-toc-创建过滤模块&quot;&gt;创建过滤模块&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#缓冲区复用&quot; id=&quot;markdown-toc-缓冲区复用&quot;&gt;缓冲区复用&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#负载均衡&quot; id=&quot;markdown-toc-负载均衡&quot;&gt;负载均衡&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#例子&quot; id=&quot;markdown-toc-例子&quot;&gt;例子&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#编程风格&quot; id=&quot;markdown-toc-编程风格&quot;&gt;编程风格&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#通用规范&quot; id=&quot;markdown-toc-通用规范&quot;&gt;通用规范&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#文件&quot; id=&quot;markdown-toc-文件&quot;&gt;文件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#注释&quot; id=&quot;markdown-toc-注释&quot;&gt;注释&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#预处理器&quot; id=&quot;markdown-toc-预处理器&quot;&gt;预处理器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#类型&quot; id=&quot;markdown-toc-类型&quot;&gt;类型&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#变量-1&quot; id=&quot;markdown-toc-变量-1&quot;&gt;变量&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#函数&quot; id=&quot;markdown-toc-函数&quot;&gt;函数&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#表达式&quot; id=&quot;markdown-toc-表达式&quot;&gt;表达式&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#条件和循环&quot; id=&quot;markdown-toc-条件和循环&quot;&gt;条件和循环&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#标签&quot; id=&quot;markdown-toc-标签&quot;&gt;标签&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#调试内存问题&quot; id=&quot;markdown-toc-调试内存问题&quot;&gt;调试内存问题&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#常见问题&quot; id=&quot;markdown-toc-常见问题&quot;&gt;常见问题&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#写c模块&quot; id=&quot;markdown-toc-写c模块&quot;&gt;写C模块&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#c字符串&quot; id=&quot;markdown-toc-c字符串&quot;&gt;C字符串&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#全局变量&quot; id=&quot;markdown-toc-全局变量&quot;&gt;全局变量&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#手动内存管理&quot; id=&quot;markdown-toc-手动内存管理&quot;&gt;手动内存管理&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#线程-1&quot; id=&quot;markdown-toc-线程-1&quot;&gt;线程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#阻塞库&quot; id=&quot;markdown-toc-阻塞库&quot;&gt;阻塞库&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#http请求到外部服务&quot; id=&quot;markdown-toc-http请求到外部服务&quot;&gt;HTTP请求到外部服务&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;简介&quot;&gt;简介&lt;/h1&gt;

&lt;h2 id=&quot;代码目录结构&quot;&gt;代码目录结构&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;auto - 构建脚本&lt;/li&gt;
  &lt;li&gt;src
    &lt;ul&gt;
      &lt;li&gt;core - 基本数据结构类型和方法：字符串，数组，日志，pool等。&lt;/li&gt;
      &lt;li&gt;event - 事件框架核心
        &lt;ul&gt;
          &lt;li&gt;modules - 事件通知模块：epoll，kqueue，select等。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;http - 核心http模块和通用代码
        &lt;ul&gt;
          &lt;li&gt;modules - 其他http模块&lt;/li&gt;
          &lt;li&gt;v2 - http2相关&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;mail - mail相关模块&lt;/li&gt;
      &lt;li&gt;os - 操作系统平台相关代码
        &lt;ul&gt;
          &lt;li&gt;unix&lt;/li&gt;
          &lt;li&gt;win32&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;stream - stream模块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;头文件&quot;&gt;头文件&lt;/h2&gt;

&lt;p&gt;下面两个头文件必须包含在所有nginx文件的开头：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include &amp;lt;ngx_config.h&amp;gt;
#include &amp;lt;ngx_core.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;另外，http相关的代码应当包含如下头文件：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include &amp;lt;ngx_http.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mail相关的代码应当包含：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include &amp;lt;ngx_mail.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Stream相关的代码应当包含：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include &amp;lt;ngx_stream.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;整数类型&quot;&gt;整数类型&lt;/h2&gt;

&lt;p&gt;为了更好的通用型目的，nginx代码提供两个整数类型：ngx_int_t和ngx_uint_t，这两个类型分别是intptr_t和uintptr_t的别名。&lt;/p&gt;

&lt;h2 id=&quot;通用返回值&quot;&gt;通用返回值&lt;/h2&gt;

&lt;p&gt;Nginx中大部分函数返回以下返回值：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;NGX_OK：操作成功时返回。&lt;/li&gt;
  &lt;li&gt;NGX_ERROR：操作失败时返回。&lt;/li&gt;
  &lt;li&gt;NGX_AGAIN：操作未完成时返回，函数后续会再次别调用。&lt;/li&gt;
  &lt;li&gt;NGX_DECLINED：操作拒绝时返回，比如，配置中关闭了某个功能可以在功能处理函数中返回该值。注意，这不是一个错误。&lt;/li&gt;
  &lt;li&gt;NGX_BUSY：资源不可用时返回。&lt;/li&gt;
  &lt;li&gt;NGX_DONE：操作完成或在其他地方继续时返回。也用作表示成功的状态码。&lt;/li&gt;
  &lt;li&gt;NGX_ABORT：函数异常退出时返回，也用作表示失败的状态码。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;错误处理&quot;&gt;错误处理&lt;/h2&gt;

&lt;p&gt;宏ngx_errno用于返回上一次的系统错误码。在POSIX系统平台它对应errno变量，在Windows系统它对应GetLastError()调用的返回值。&lt;/p&gt;

&lt;p&gt;宏ngx_socket_errno用于返回上一次的socket错误码。和ngx_errno宏一样，在POSIX系统平台它对应errno变量，但在Windows系统它对应WSAGetLastError()调用的返回值。&lt;/p&gt;

&lt;p&gt;多次访问ngx_errno和ngx_socket_errno宏的值可能带来性能问题。如果一个错误值可能被使用多次，请将它保存在ngx_err_t类型的本次变量中使用。&lt;/p&gt;

&lt;p&gt;设置错误使用ngx_set_errno(errno)和ngx_set_socket_errno(errno)两个宏。&lt;/p&gt;

&lt;p&gt;ngx_errno和ngx_socket_errno宏的值可以传递给打印日志的函数ngx_log_error()和ngx_log_debugX()，此时，系统错误文本会添加到日志中。&lt;/p&gt;

&lt;p&gt;下面是使用ngx_errno的一个例子：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ngx_int_t
ngx_my_kill(ngx_pid_t pid, ngx_log_t *log, int signo)
{
    ngx_err_t  err;

    if (kill(pid, signo) == -1) {
        err = ngx_errno;

        ngx_log_error(NGX_LOG_ALERT, log, err, &quot;kill(%P, %d) failed&quot;, pid, signo);

        if (err == NGX_ESRCH) {
            return 2;
        }

        return 1;
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;字符串-string&quot;&gt;字符串 String&lt;/h1&gt;

&lt;h2 id=&quot;简介-1&quot;&gt;简介&lt;/h2&gt;

&lt;p&gt;在Nginx中使用无符号字符指针 u_char*来表示C字符串。&lt;/p&gt;

&lt;p&gt;Nginx的字符串类型ngx_str_t的定义如下：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;typedef struct {
    size_t      len;
    u_char     *data;
} ngx_str_t;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;其中，len保存了字符串的长度，data保存了字符串数据。&lt;/p&gt;

&lt;p&gt;ngx_str_t保存的字符串末尾可能包含\0也可能不包含。大部分情况下是不包含\0结尾的。&lt;/p&gt;

&lt;p&gt;但是在某些代码中（比如，解析配置的代码），ngx_str_t表示的字符串是以\0结尾的，这么做的目的是简化字符串比较和更易于向系统调用传递字符串。&lt;/p&gt;

&lt;p&gt;Nginx中的字符串操作在src/core/ngx_string.h中定义，其中很多是对标准C函数的简单封装，如：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_strcmp()&lt;/li&gt;
  &lt;li&gt;ngx_strncmp()&lt;/li&gt;
  &lt;li&gt;ngx_strstr()&lt;/li&gt;
  &lt;li&gt;ngx_strlen()&lt;/li&gt;
  &lt;li&gt;ngx_strchr()&lt;/li&gt;
  &lt;li&gt;ngx_memcmp()&lt;/li&gt;
  &lt;li&gt;ngx_memset()&lt;/li&gt;
  &lt;li&gt;ngx_memcpy()&lt;/li&gt;
  &lt;li&gt;ngx_memmove()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;其他的字符串函数是Nginx特有的：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_memzero() - 用0填充内存&lt;/li&gt;
  &lt;li&gt;ngx_explicit_memzero() - 和ngx_memzero()一样，但这个函数永远不会被编译器的dead-store-elimination优化所移除。该方法可用于清除敏感数据，如密码，私钥等。&lt;/li&gt;
  &lt;li&gt;ngx_cpymem() - 和ngx_memcpy()一样，但返回最终的目的地址，因此，可用于一次串联多个字符串。&lt;/li&gt;
  &lt;li&gt;ngx_movemem() - 和ngx_memmove()一样，但返回最终的目的地址。&lt;/li&gt;
  &lt;li&gt;ngx_strlchr - 字符串中查找某个字符，源字符串使用首尾地址界定。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下方法用于字符串的大小写转化和比较：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_tolower()&lt;/li&gt;
  &lt;li&gt;ngx_toupper()&lt;/li&gt;
  &lt;li&gt;ngx_strlow()&lt;/li&gt;
  &lt;li&gt;ngx_strcasecmp()&lt;/li&gt;
  &lt;li&gt;ngx_strncasecmp()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下宏用于简化字符串初始化：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_string(text) - 从C字符串常量text中初始化ngx_str_t类型字符串&lt;/li&gt;
  &lt;li&gt;ngx_null_string - 初始化一个ngx_str_t类型的空字符串&lt;/li&gt;
  &lt;li&gt;ngx_str_set(str, text) - 从C字符串常量text中初始化ngx_str_t类型字符串变量str&lt;/li&gt;
  &lt;li&gt;ngx_str_null(str) - 以空字符串初始化ngx_str_t类型字符串str&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;字符串格式化&quot;&gt;字符串格式化&lt;/h2&gt;

&lt;p&gt;以下格式化方式支持Nginx特有的类型：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_sprintf(buf, fmt, …)&lt;/li&gt;
  &lt;li&gt;ngx_snprintf(buf, max, fmt, …)&lt;/li&gt;
  &lt;li&gt;ngx_slprintf(buf, last, fmt, …)&lt;/li&gt;
  &lt;li&gt;ngx_vslprintf(buf, last, fmt, args)&lt;/li&gt;
  &lt;li&gt;ngx_vsnprintf(buf, max, fmt, args)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;这些格式化方法支持的格式化参数的完整列表在src/core/ngx_string.c文件中定义。&lt;/p&gt;

&lt;p&gt;部分参数如下：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;%O - off_t&lt;/li&gt;
  &lt;li&gt;%T - time_t&lt;/li&gt;
  &lt;li&gt;%z - ssize_t&lt;/li&gt;
  &lt;li&gt;%i - ngx_int_t&lt;/li&gt;
  &lt;li&gt;%p - void *&lt;/li&gt;
  &lt;li&gt;%V - ngx_str_t *&lt;/li&gt;
  &lt;li&gt;%s - u_char *&lt;/li&gt;
  &lt;li&gt;%*s - size_t + u_char *
**&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;你可以在大部分类型前面前置u使其成为无符号类型。如果要转化成16进制输出，使用X或者x。&lt;/p&gt;

&lt;p&gt;例如：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;u_char      buf[NGX_INT_T_LEN];
size_t      len;
ngx_uint_t  n;

/* set n here */

len = ngx_sprintf(buf, &quot;%ui&quot;, n) — buf;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;数字转换&quot;&gt;数字转换&lt;/h2&gt;

&lt;p&gt;Nginx中实现了多种数字转换方法。&lt;/p&gt;

&lt;p&gt;以下四个函数将给定长度的字符串转换为指定类型的正整数。错误返回NGX_ERROR。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_atoi(line, n) - ngx_int_t&lt;/li&gt;
  &lt;li&gt;ngx_atosz(line, n) - ssize_t&lt;/li&gt;
  &lt;li&gt;ngx_atoof(line, n) - off_t&lt;/li&gt;
  &lt;li&gt;ngx_atotm(line, n) - time_t&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;下面两个数字转换函数，错误也返回NGX_ERROR。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ngx_atofp(line, n, point) - 字符串表示的浮点数转换为ngx_int_t类型正整数。结果会将小数点左移若干位，位数由point参数指定。比如，ngx_atofp(“10.5”, 4, 2)返回1050。&lt;/li&gt;
  &lt;li&gt;ngx_hextoi(line, n) - 将十六进制表示的正整数转换为ngx_int_t类型正整数。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;正则表达式&quot;&gt;正则表达式&lt;/h2&gt;

&lt;h1 id=&quot;时间&quot;&gt;时间&lt;/h1&gt;

&lt;h1 id=&quot;容器类型&quot;&gt;容器类型&lt;/h1&gt;

&lt;h2 id=&quot;数组-array&quot;&gt;数组 Array&lt;/h2&gt;

&lt;h2 id=&quot;链表-list&quot;&gt;链表 List&lt;/h2&gt;

&lt;h2 id=&quot;双向链表-queue&quot;&gt;双向链表 Queue&lt;/h2&gt;

&lt;h2 id=&quot;红黑树-rb-tree&quot;&gt;红黑树 RB-Tree&lt;/h2&gt;

&lt;h2 id=&quot;哈希表-hash&quot;&gt;哈希表 Hash&lt;/h2&gt;

&lt;h3 id=&quot;通配符匹配&quot;&gt;通配符匹配&lt;/h3&gt;

&lt;h1 id=&quot;内存管理&quot;&gt;内存管理&lt;/h1&gt;

&lt;h2 id=&quot;堆栈-heap&quot;&gt;堆栈 Heap&lt;/h2&gt;

&lt;h2 id=&quot;池-pool&quot;&gt;池 Pool&lt;/h2&gt;

&lt;h2 id=&quot;共享内存&quot;&gt;共享内存&lt;/h2&gt;

&lt;h1 id=&quot;日志&quot;&gt;日志&lt;/h1&gt;

&lt;h1 id=&quot;生命周期-cycle&quot;&gt;生命周期 Cycle&lt;/h1&gt;

&lt;h1 id=&quot;缓冲区-buffer&quot;&gt;缓冲区 Buffer&lt;/h1&gt;

&lt;h1 id=&quot;网络&quot;&gt;网络&lt;/h1&gt;

&lt;h2 id=&quot;链接-connection&quot;&gt;链接 Connection&lt;/h2&gt;

&lt;h1 id=&quot;事件驱动&quot;&gt;事件驱动&lt;/h1&gt;

&lt;h2 id=&quot;事件&quot;&gt;事件&lt;/h2&gt;

&lt;h2 id=&quot;io-事件&quot;&gt;I/O 事件&lt;/h2&gt;

&lt;h2 id=&quot;定时器事件&quot;&gt;定时器事件&lt;/h2&gt;

&lt;h2 id=&quot;后处理事件&quot;&gt;后处理事件&lt;/h2&gt;

&lt;h2 id=&quot;事件循环&quot;&gt;事件循环&lt;/h2&gt;

&lt;h1 id=&quot;进程&quot;&gt;进程&lt;/h1&gt;

&lt;h1 id=&quot;线程&quot;&gt;线程&lt;/h1&gt;

&lt;h1 id=&quot;模块&quot;&gt;模块&lt;/h1&gt;

&lt;h2 id=&quot;添加新模块&quot;&gt;添加新模块&lt;/h2&gt;

&lt;h2 id=&quot;核心模块&quot;&gt;核心模块&lt;/h2&gt;

&lt;h2 id=&quot;配置指令&quot;&gt;配置指令&lt;/h2&gt;

&lt;h1 id=&quot;http&quot;&gt;HTTP&lt;/h1&gt;

&lt;h2 id=&quot;链接-connction&quot;&gt;链接 Connction&lt;/h2&gt;

&lt;h2 id=&quot;请求-request&quot;&gt;请求 Request&lt;/h2&gt;

&lt;h2 id=&quot;配置&quot;&gt;配置&lt;/h2&gt;

&lt;h2 id=&quot;处理阶段&quot;&gt;处理阶段&lt;/h2&gt;

&lt;h2 id=&quot;变量&quot;&gt;变量&lt;/h2&gt;

&lt;h2 id=&quot;访问已存在的变量&quot;&gt;访问已存在的变量&lt;/h2&gt;

&lt;h2 id=&quot;创建新变量&quot;&gt;创建新变量&lt;/h2&gt;

&lt;h2 id=&quot;复杂值&quot;&gt;复杂值&lt;/h2&gt;

&lt;h2 id=&quot;请求重定向&quot;&gt;请求重定向&lt;/h2&gt;

&lt;h2 id=&quot;子请求&quot;&gt;子请求&lt;/h2&gt;

&lt;h2 id=&quot;终止请求&quot;&gt;终止请求&lt;/h2&gt;

&lt;h2 id=&quot;请求体&quot;&gt;请求体&lt;/h2&gt;

&lt;h2 id=&quot;响应&quot;&gt;响应&lt;/h2&gt;

&lt;h2 id=&quot;响应头&quot;&gt;响应头&lt;/h2&gt;

&lt;h2 id=&quot;响应头过滤处理&quot;&gt;响应头过滤处理&lt;/h2&gt;

&lt;h2 id=&quot;响应体&quot;&gt;响应体&lt;/h2&gt;

&lt;h2 id=&quot;响应体过滤处理&quot;&gt;响应体过滤处理&lt;/h2&gt;

&lt;h2 id=&quot;创建过滤模块&quot;&gt;创建过滤模块&lt;/h2&gt;

&lt;h2 id=&quot;缓冲区复用&quot;&gt;缓冲区复用&lt;/h2&gt;

&lt;h2 id=&quot;负载均衡&quot;&gt;负载均衡&lt;/h2&gt;

&lt;h1 id=&quot;例子&quot;&gt;例子&lt;/h1&gt;

&lt;h1 id=&quot;编程风格&quot;&gt;编程风格&lt;/h1&gt;

&lt;h2 id=&quot;通用规范&quot;&gt;通用规范&lt;/h2&gt;

&lt;h2 id=&quot;文件&quot;&gt;文件&lt;/h2&gt;

&lt;h2 id=&quot;注释&quot;&gt;注释&lt;/h2&gt;

&lt;h2 id=&quot;预处理器&quot;&gt;预处理器&lt;/h2&gt;

&lt;h2 id=&quot;类型&quot;&gt;类型&lt;/h2&gt;

&lt;h2 id=&quot;变量-1&quot;&gt;变量&lt;/h2&gt;

&lt;h2 id=&quot;函数&quot;&gt;函数&lt;/h2&gt;

&lt;h2 id=&quot;表达式&quot;&gt;表达式&lt;/h2&gt;

&lt;h2 id=&quot;条件和循环&quot;&gt;条件和循环&lt;/h2&gt;

&lt;h2 id=&quot;标签&quot;&gt;标签&lt;/h2&gt;

&lt;h1 id=&quot;调试内存问题&quot;&gt;调试内存问题&lt;/h1&gt;

&lt;h1 id=&quot;常见问题&quot;&gt;常见问题&lt;/h1&gt;

&lt;h2 id=&quot;写c模块&quot;&gt;写C模块&lt;/h2&gt;

&lt;h2 id=&quot;c字符串&quot;&gt;C字符串&lt;/h2&gt;

&lt;h2 id=&quot;全局变量&quot;&gt;全局变量&lt;/h2&gt;

&lt;h2 id=&quot;手动内存管理&quot;&gt;手动内存管理&lt;/h2&gt;

&lt;h2 id=&quot;线程-1&quot;&gt;线程&lt;/h2&gt;

&lt;h2 id=&quot;阻塞库&quot;&gt;阻塞库&lt;/h2&gt;

&lt;h2 id=&quot;http请求到外部服务&quot;&gt;HTTP请求到外部服务&lt;/h2&gt;
</description>
        <pubDate>Thu, 18 Feb 2021 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/ngx-devel-guide/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/ngx-devel-guide/</guid>
      </item>
    
      <item>
        <title>ngx_http_core_module模块</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#listen指令&quot; id=&quot;markdown-toc-listen指令&quot;&gt;listen指令&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#addressport&quot; id=&quot;markdown-toc-addressport&quot;&gt;address[:port]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#default_server&quot; id=&quot;markdown-toc-default_server&quot;&gt;default_server&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#ssl&quot; id=&quot;markdown-toc-ssl&quot;&gt;ssl&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#http2&quot; id=&quot;markdown-toc-http2&quot;&gt;http2&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#spdy&quot; id=&quot;markdown-toc-spdy&quot;&gt;spdy&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#proxy_protocol&quot; id=&quot;markdown-toc-proxy_protocol&quot;&gt;proxy_protocol&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#socket相关选项&quot; id=&quot;markdown-toc-socket相关选项&quot;&gt;socket相关选项&lt;/a&gt;        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#setfibnumber&quot; id=&quot;markdown-toc-setfibnumber&quot;&gt;setfib=number&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#fastopennumber&quot; id=&quot;markdown-toc-fastopennumber&quot;&gt;fastopen=number&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#backlognumber&quot; id=&quot;markdown-toc-backlognumber&quot;&gt;backlog=number&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#rcvbufsndbufnumber&quot; id=&quot;markdown-toc-rcvbufsndbufnumber&quot;&gt;rcvbuf/sndbuf=number&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#accept_filterfilter&quot; id=&quot;markdown-toc-accept_filterfilter&quot;&gt;accept_filter=filter&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#deferred&quot; id=&quot;markdown-toc-deferred&quot;&gt;deferred&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#bind&quot; id=&quot;markdown-toc-bind&quot;&gt;bind&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#ipv6onlyonoff&quot; id=&quot;markdown-toc-ipv6onlyonoff&quot;&gt;ipv6only=on|off&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#reuseport&quot; id=&quot;markdown-toc-reuseport&quot;&gt;reuseport&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#so_keepaliveonoffkeepidlekeepintvlkeepcnt&quot; id=&quot;markdown-toc-so_keepaliveonoffkeepidlekeepintvlkeepcnt&quot;&gt;so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#例子&quot; id=&quot;markdown-toc-例子&quot;&gt;例子&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;listen指令&quot;&gt;listen指令&lt;/h1&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:     listen address[:port] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;default_server] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ssl] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;http2 | spdy] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;proxy_protocol]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;setfib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fastopen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;backlog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;rcvbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sndbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;accept_filter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;filter] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;deferred] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ipv6only&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;on|off] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;reuseport]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;so_keepalive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;on|off|[keepidle]:[keepintvl]:[keepcnt]]&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            listen port &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;default_server] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ssl] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;http2 | spdy] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;proxy_protocol] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;setfib&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fastopen&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;backlog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;rcvbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sndbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;accept_filter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;filter]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;deferred] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ipv6only&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;on|off] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;reuseport] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;so_keepalive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;on|off|[keepidle]:[keepintvl]:[keepcnt]]&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            listen unix:path &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;default_server] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ssl] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;http2 | spdy] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;proxy_protocol]
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;backlog&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;number] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;rcvbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;sndbuf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;size] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;accept_filter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;filter] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;deferred] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
                  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;so_keepalive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;on|off|[keepidle]:[keepintvl]:[keepcnt]]&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
Default:    listen &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;:80 | &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
Context:    server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;addressport&quot;&gt;address[:port]&lt;/h2&gt;
&lt;p&gt;设置监听地址和端口或者Unix Domain Socket的文件路径，用于服务器接收请求。
可以同时设定地址和端口，也可以只设定地址或只设定端口。地址也可以是域名，比如：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;listen 127.0.0.1:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
listen 127.0.0.1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
listen 8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
listen &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
listen localhost:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;IPV6地址在中括号中指定：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;listen &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;::]:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
listen &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;::1]&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;指定Unix Doamin Socket以&lt;em&gt;unix:&lt;/em&gt;开头：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;listen unix:/var/run/nginx.sock&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果只指定了地址，端口会默认使用80。如果没有配置listen指令，端口会使用80，如果80不可用则使用8000。&lt;/p&gt;

&lt;h2 id=&quot;default_server&quot;&gt;default_server&lt;/h2&gt;
&lt;p&gt;指定默认主机，如果不指定，第一个会作为默认主机。&lt;/p&gt;

&lt;h2 id=&quot;ssl&quot;&gt;ssl&lt;/h2&gt;
&lt;p&gt;指示所有经过该端口接收的请求应该以SSL模式工作。&lt;/p&gt;

&lt;h2 id=&quot;http2&quot;&gt;http2&lt;/h2&gt;
&lt;p&gt;配置端口接收HTTP2连接。一般情况下，应该同时开启ssl选项，但Nginx也可以配置成不适用SSL接收HTTP2连接。&lt;/p&gt;

&lt;h2 id=&quot;spdy&quot;&gt;spdy&lt;/h2&gt;
&lt;p&gt;配置端口接收SPDY连接。一般情况下，应该同时开启ssl选项，但Nginx也可以配置成不适用SSL接收SPDY连接。&lt;/p&gt;

&lt;h2 id=&quot;proxy_protocol&quot;&gt;proxy_protocol&lt;/h2&gt;
&lt;p&gt;指示所有经过该端口接收的请求都适用PROXY协议。&lt;/p&gt;

&lt;h2 id=&quot;socket相关选项&quot;&gt;socket相关选项&lt;/h2&gt;
&lt;p&gt;listen指令还提供了一些和socket系统调用相关的配置选项。这些配置选项可以再任何listen指令中指定，但每个address:port对只能指定一次。&lt;/p&gt;

&lt;h3 id=&quot;setfibnumber&quot;&gt;setfib=number&lt;/h3&gt;
&lt;p&gt;当前仅FreeBSD有效。&lt;/p&gt;

&lt;h3 id=&quot;fastopennumber&quot;&gt;fastopen=number&lt;/h3&gt;
&lt;p&gt;为监听的socket开启TCP Fast Open功能，并指定尚未完成三次握手的连接队列的最大长度。&lt;/p&gt;

&lt;h3 id=&quot;backlognumber&quot;&gt;backlog=number&lt;/h3&gt;
&lt;p&gt;指定listen()调用的backlog参数，以限制pending连接队列的最大长度。
默认情况下，FreeBSD，DragonBSD和MacOS系统backlog设置为-1，其他平台设置为511。&lt;/p&gt;

&lt;h3 id=&quot;rcvbufsndbufnumber&quot;&gt;rcvbuf/sndbuf=number&lt;/h3&gt;
&lt;p&gt;为监听socket设置接收缓冲区大小和发送缓冲区大小。&lt;/p&gt;

&lt;h3 id=&quot;accept_filterfilter&quot;&gt;accept_filter=filter&lt;/h3&gt;
&lt;p&gt;仅FreeBSD和NetBSD 5.0+有效。&lt;/p&gt;

&lt;h3 id=&quot;deferred&quot;&gt;deferred&lt;/h3&gt;
&lt;p&gt;在Linux系统上指示使用deferred accept()（TCP_DEFER_ACCEPT的socket选项）。&lt;/p&gt;

&lt;h3 id=&quot;bind&quot;&gt;bind&lt;/h3&gt;
&lt;p&gt;针对给定的address:port对单独执行bind()调用。如果存在不同的address但相同port的多个listen指令，并且有一个listen指令监听了指定端口的所有地址(&lt;em&gt;:port)，此时nginx只会对&lt;/em&gt;:port执行bind()。
值得注意的是，此时getsockname()系统调用可用于确定接收连接的address。如果给定的address:port对指定了setfib, backlog, rcvbuf, sndbuf, accept_filter, deferred, ipv6only 或 so_keepalive 参数，那么始终会单独执行bind()。&lt;/p&gt;

&lt;h3 id=&quot;ipv6onlyonoff&quot;&gt;ipv6only=on|off&lt;/h3&gt;
&lt;p&gt;该参数（通过IPV6_V6ONLY socket选项）用于决定一个监听了通配符(::)地址的IPv6 socket是仅接收IPv6连接还是IPv6和IPv4连接都接收。
该选项默认开启。仅在启动时设置一次。&lt;/p&gt;

&lt;h3 id=&quot;reuseport&quot;&gt;reuseport&lt;/h3&gt;
&lt;p&gt;该参数指示为每个worker进程创建单独的监听socket，允许内核在worker进程间分配进入的连接。
该参数当前仅在linux 3.9+，DragonFly BSD和FreeBSD 12+有效。&lt;/p&gt;

&lt;h3 id=&quot;so_keepaliveonoffkeepidlekeepintvlkeepcnt&quot;&gt;so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]&lt;/h3&gt;
&lt;p&gt;该参数用于为监听socket设定”TCP keepalive”行为。如果没有设置该选项，将应用操作系统设置。
如果设置为”on”，socket将开启SO_KEEPALIVE选项。如果设置为”off”，会关闭SO_KEEPALIVE选项。
有些操作系统支持为每个socket设定TCP keepalive参数，这些参数包括TCP_KEEPIDLE, TCP_KEEPINTVL和 TCP_KEEPCNT。
在这些操作系统（如linux 2.4+）中可以使用keepidle, keepintvl和 keepcnt配置参数。
可以不设置一个或两个参数，此时使用操作系统设置作为对应的参数设置。例如：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;so_keepalive=30m::10
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;此时，会设置空闲超时时间（TCP_KEEPIDLE）30分钟，探测时间间隔（TCP_KEEPINTVL）则使用系统默认值，探测次数（TCP_KEEPCNT）设置为10次。&lt;/p&gt;

&lt;h2 id=&quot;例子&quot;&gt;例子&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;listen 127.0.0.1 default_server accept_filter=dataready backlog=1024;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://nginx.org/en/docs/http/ngx_http_core_module.html#listen&quot;&gt;Nginx listen&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
        <pubDate>Thu, 15 Aug 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/ngx_http_core_module/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/ngx_http_core_module/</guid>
      </item>
    
      <item>
        <title>Nginx模块梳理</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;当前Nginx共提供111个模块，分类如下：&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;10个core模块&quot;&gt;10个CORE模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_core_module
    &lt;ul&gt;
      &lt;li&gt;提供main conf下的指令，如deamon等&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_errlog_module
    &lt;ul&gt;
      &lt;li&gt;仅提供errlog指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_events_module
    &lt;ul&gt;
      &lt;li&gt;仅提供event指令块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_http_module
    &lt;ul&gt;
      &lt;li&gt;仅提供http指令块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_mail_module
    &lt;ul&gt;
      &lt;li&gt;仅提供mail指令块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_stream_module
    &lt;ul&gt;
      &lt;li&gt;仅提供stream指令块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_thread_pool_module
    &lt;ul&gt;
      &lt;li&gt;仅提供thread_pool指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_regex_module
    &lt;ul&gt;
      &lt;li&gt;仅提供pcre_jit指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_openssl_module
    &lt;ul&gt;
      &lt;li&gt;仅提供ssl_engine指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;ngx_google_perftools_module
    &lt;ul&gt;
      &lt;li&gt;仅提供google_perftools_profiles指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;1个conf模块&quot;&gt;1个CONF模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_conf_module
    &lt;ul&gt;
      &lt;li&gt;仅提供include指令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;9个event模块&quot;&gt;9个EVENT模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_event_core_module&lt;/li&gt;
  &lt;li&gt;ngx_epoll_module&lt;/li&gt;
  &lt;li&gt;ngx_select_module&lt;/li&gt;
  &lt;li&gt;ngx_kqueue_module&lt;/li&gt;
  &lt;li&gt;ngx_poll_module&lt;/li&gt;
  &lt;li&gt;ngx_devpoll_module&lt;/li&gt;
  &lt;li&gt;ngx_eventport_module&lt;/li&gt;
  &lt;li&gt;ngx_win32_poll_module&lt;/li&gt;
  &lt;li&gt;ngx_win32_select_module&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;65个http模块&quot;&gt;65个HTTP模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_http_core_module&lt;/li&gt;
  &lt;li&gt;略&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;19个stream模块&quot;&gt;19个STREAM模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_stream_core_module&lt;/li&gt;
  &lt;li&gt;略&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;7个mail模块&quot;&gt;7个MAIL模块&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;ngx_mail_core_module&lt;/li&gt;
  &lt;li&gt;略&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Fri, 26 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/nginx/2019/07/26/nginx-modules/</link>
        <guid isPermaLink="true">https://yanl.cc/nginx/2019/07/26/nginx-modules/</guid>
      </item>
    
      <item>
        <title>虚拟主机名称</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#正则表达式名字&quot; id=&quot;markdown-toc-正则表达式名字&quot;&gt;正则表达式名字&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#其他类型的名字&quot; id=&quot;markdown-toc-其他类型的名字&quot;&gt;其他类型的名字&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#优化&quot; id=&quot;markdown-toc-优化&quot;&gt;优化&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;虚拟主机名使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server_name&lt;/code&gt;指令定义，用于决定由某台虚拟主机来处理请求。虚拟主机名可以使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;确切的名字，通配符，或者是正则表达式&lt;/code&gt;来定义：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  example.org  www.example.org;
    ...
}

server {
    listen       80;
    server_name  *.example.org;
    ...
}

server {
    listen       80;
    server_name  mail.*;
    ...
}

server {
    listen       80;
    server_name  ~^(?&amp;lt;user&amp;gt;.+)\.example\.net$;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;nginx以名字查找虚拟主机时，如果名字可以匹配多于一个主机名定义，比如同时匹配了通配符的名字和正则表达式的名字，那么nginx按照&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;下面的优先级别&lt;/code&gt;进行查找，并选中第一个匹配的虚拟主机：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;确切的名字；&lt;/li&gt;
  &lt;li&gt;最长的以星号起始的通配符名字：*.example.org；&lt;/li&gt;
  &lt;li&gt;最长的以星号结束的通配符名字：mail.*；&lt;/li&gt;
  &lt;li&gt;第一个匹配的正则表达式名字（按在配置文件中出现的顺序）。&lt;/li&gt;
  &lt;li&gt;通配符名字&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;通配符名字只可以在名字的起始处或结尾处包含一个星号，并且星号与其他字符之间用点分隔&lt;/strong&gt;。所以，“www.*.example.org”和“w*.example.org”都是非法的。不过，上面的两个名字可以使用正则表达式描述，即“~^www..+.example.org$”和“~^w.*.example.org$”。星号可以匹配名字的多个节（各节都是以点号分隔的）。“*.example.org”不仅匹配www.example.org，也匹配www.sub.example.org。&lt;/p&gt;

&lt;p&gt;有一种形如“.example.org”的特殊通配符，它可以既匹配确切的名字“example.org”，又可以匹配一般的通配符名字“*.example.org”。&lt;/p&gt;

&lt;h2 id=&quot;正则表达式名字&quot;&gt;正则表达式名字&lt;/h2&gt;

&lt;p&gt;nginx使用的正则表达式兼容PCRE。为了使用正则表达式，虚拟主机名必须以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;波浪线“~”&lt;/code&gt;起始：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server_name  ~^www\d+\.example\.net$;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;否则该名字会被认为是个确切的名字，如果表达式含星号，则会被认为是个通配符名字（而且很可能是一个非法的通配符名字）。不要忘记设置“^”和“$”锚点，语法上它们不是必须的，但是逻辑上是的。同时需要注意的是，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;域名中的点“.”需要用反斜线“\”转义&lt;/code&gt;。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;含有“{”和“}”的正则表达式需要被引用&lt;/code&gt;，如：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server_name  &quot;~^(?&amp;lt;name&amp;gt;\w\d{1,3}+)\.example\.net$&quot;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;否则nginx就不能启动，错误提示是：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;directive &quot;server_name&quot; is not terminated by &quot;;&quot; in ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;命名的正则表达式捕获组在后面可以作为变量使用：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    server_name   ~^(www\.)?(?&amp;lt;domain&amp;gt;.+)$;

    location / {
        root   /sites/$domain;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;PCRE使用下面语法支持命名捕获组：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;?&amp;lt;name&amp;gt;    从PCRE-7.0开始支持，兼容Perl 5.10语法
?&apos;name&apos;    从PCRE-7.0开始支持，兼容Perl 5.10语法
?P&amp;lt;name&amp;gt;    从PCRE-4.0开始支持，兼容Python语法
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果nginx不能启动，并显示错误信息：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pcre_compile() failed: unrecognized character after (?&amp;lt; in ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;说明PCRE版本太旧，应该尝试使用?P&lt;name&gt;。捕获组也可以以数字方式引用：&lt;/name&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    server_name   ~^(www\.)?(.+)$;

    location / {
        root   /sites/$2;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;不过，这种用法只限于简单的情况（比如上面的例子），因为数字引用很容易被覆盖。&lt;/p&gt;

&lt;h2 id=&quot;其他类型的名字&quot;&gt;其他类型的名字&lt;/h2&gt;

&lt;p&gt;有一些主机名会被特别对待。&lt;/p&gt;

&lt;p&gt;如果需要用一个非默认的虚拟主机处理请求头中不含“Host”字段的请求，需要指定一个空名字：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  example.org  www.example.org  &quot;&quot;;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果server块中没有定义server_name，nginx使用空名字作为虚拟主机名。&lt;/p&gt;

&lt;p&gt;nginx 0.8.48版本以下（含）在同样的情况下会使用机器名作为虚拟主机名。
如果以“$hostname”（nginx 0.9.4及以上版本）定义虚拟主机名，机器名将被使用。&lt;/p&gt;

&lt;p&gt;如果使用IP地址而不是主机名来请求服务器，那么请求头的“Host”字段包含的将是IP地址。可以将IP地址作为虚拟主机名来处理这种请求：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  nginx.org
                 www.nginx.org
                 &quot;&quot;
                 192.168.1.1
                 ;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在匹配所有的服务器的例子中，可以见到一个奇怪的名字&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;“_”&lt;/code&gt;：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80  default_server;
    server_name  _;
    return       444;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这没什么特别的，它只不过是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;成千上万的与真实的名字绝无冲突的非法域名中的一个&lt;/code&gt;而已。当然，也可以使用“–”和“!@#”等等。&lt;/p&gt;

&lt;p&gt;nginx直到0.6.25版本还支持一个特殊的名字&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;“*”&lt;/code&gt;，这个名字一直被错误地理解成是一个匹配所有的名字。但它从来没有像匹配所有的名字，或者通配符那样工作过，而是用来支持一种功能，此功能现在已经改由&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server_name_in_redirect指令&lt;/code&gt;提供支持了。所以，现在这个特殊的名字“*”已经过时了，应该使用server_name_in_redirect指令取代它。需要注意的是，&lt;strong&gt;使用server_name指令无法描述匹配所有的名字或者默认服务器&lt;/strong&gt;。这是listen指令的属性，而不是server_name指令的属性。可以定义两个服务器都监听*:80和*:8080端口，然后指定一个作为端口*:8080的默认服务器，另一个作为端口*:80的默认服务器：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    listen       8080  default_server;
    server_name  example.net;
    ...
}

server {
    listen       80  default_server;
    listen       8080;
    server_name  example.org;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;优化&quot;&gt;优化&lt;/h2&gt;
&lt;p&gt;确切名字和通配符名字存储在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;哈希表&lt;/code&gt;中。哈希表和监听端口关联。哈希表的尺寸在配置阶段进行了优化，可以以最小的CPU缓存命中失败来找到名字。设置哈希表的细节参见&lt;a href=&quot;http://nginx.org/en/docs/hash.html&quot;&gt;这篇文档&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;nginx首先搜索确切名字的哈希表，如果没有找到，搜索以星号起始的通配符名字的哈希表，如果还是没有找到，继续搜索以星号结束的通配符名字的哈希表。&lt;/p&gt;

&lt;p&gt;因为名字是按照域名的节来搜索的，所以搜索通配符名字的哈希表比搜索确切名字的哈希表慢。注意特殊的通配符名字“.example.org”存储在通配符名字的哈希表中，而不在确切名字的哈希表中。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;正则表达式是一个一个串行的测试，所以是最慢的，而且不可扩展。&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;鉴于以上原因，请尽可能使用确切的名字。举个例子，如果使用example.org和www.example.org来访问服务器是最频繁的，那么将它们明确的定义出来就更为有效：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  example.org  www.example.org  *.example.org;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下面这种方法相比更简单，但是效率也更低：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  .example.org;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果定义了大量名字，或者定义了非常长的名字，那可能需要在http配置块中使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server_names_hash_max_size&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server_names_hash_bucket_size&lt;/code&gt;指令进行调整。server_names_hash_bucket_size的默认值可能是32，或者是64，或者是其他值，取决于CPU的缓存行的长度。如果这个值是32，那么定义“too.long.server.name.example.org”作为虚拟主机名就会失败，而nginx显示下面错误信息：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;could not build the server_names_hash,
you should increase server_names_hash_bucket_size: 32
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;出现了这种情况，那就需要将指令的值扩大一倍：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http {
    server_names_hash_bucket_size  64;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果定义了大量名字，得到了另外一个错误：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;could not build the server_names_hash,
you should increase either server_names_hash_max_size: 512
or server_names_hash_bucket_size: 32
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;那么应该先尝试设置server_names_hash_max_size的值差不多等于名字列表的名字总量。如果还不能解决问题，或者服务器启动非常缓慢，再尝试提高server_names_hash_bucket_size的值。&lt;/p&gt;

&lt;p&gt;如果只为一个监听端口配置了唯一的主机，那么nginx就完全不会测试虚拟主机名了（也不会为监听端口建立哈希表）。不过，有一个例外，如果定义的虚拟主机名是一个含有捕获组的正则表达式，这时nginx就不得不执行这个表达式以得到捕获组。&lt;/p&gt;
</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/server-names/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/server-names/</guid>
      </item>
    
      <item>
        <title>Nginx如何处理请求</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#基于名字的虚拟主机&quot; id=&quot;markdown-toc-基于名字的虚拟主机&quot;&gt;基于名字的虚拟主机&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#如何防止处理未定义主机名的请求&quot; id=&quot;markdown-toc-如何防止处理未定义主机名的请求&quot;&gt;如何防止处理未定义主机名的请求&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#基于域名和ip混合的虚拟主机&quot; id=&quot;markdown-toc-基于域名和ip混合的虚拟主机&quot;&gt;基于域名和IP混合的虚拟主机&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#一个简单php站点配置&quot; id=&quot;markdown-toc-一个简单php站点配置&quot;&gt;一个简单PHP站点配置&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;基于名字的虚拟主机&quot;&gt;基于名字的虚拟主机&lt;/h2&gt;
&lt;p&gt;Nginx首先选定由哪一个虚拟主机来处理请求。让我们从一个简单的配置（其中全部3个虚拟主机都在端口*:80上监听）开始：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

server {
    listen      80;
    server_name example.com www.example.com;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在这个配置中，nginx仅仅检查请求的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Host&lt;/code&gt;头以决定该请求应由哪个虚拟主机来处理。
如果Host头没有匹配任意一个虚拟主机，或者请求中根本没有包含Host头，那nginx会将请求分发到定义在此端口上的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;默认虚拟主机&lt;/code&gt;。
在以上配置中，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第一个被列出的虚拟主机即nginx的默认虚拟主机——这是nginx的默认行为&lt;/code&gt;。
而且，可以显式地设置某个主机为默认虚拟主机，即在”listen”指令中设置”default_server”参数：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;“default_server”参数从0.8.21版开始可用。在之前的版本中，应该使用”default”参数代替。
请注意”default_server”是监听端口的属性，而不是主机名的属性。后面会对此有更多介绍。&lt;/p&gt;

&lt;h2 id=&quot;如何防止处理未定义主机名的请求&quot;&gt;如何防止处理未定义主机名的请求&lt;/h2&gt;
&lt;p&gt;如果不允许请求中缺少Host头，可以定义如下主机，丢弃这些请求：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  &quot;&quot;;
    return       444;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在这里，我们设置主机名为空字符串以匹配未定义Host头的请求，而且返回了一个nginx特有的，非http标准的返回码444，它可以用来关闭连接。&lt;/p&gt;

&lt;p&gt;从0.8.48版本开始，这已成为主机名的默认设置，所以可以省略server_name ““。而之前的版本使用机器的hostname作为主机名的默认值。&lt;/p&gt;

&lt;h2 id=&quot;基于域名和ip混合的虚拟主机&quot;&gt;基于域名和IP混合的虚拟主机&lt;/h2&gt;
&lt;p&gt;下面让我们来看一个复杂点的配置，在这个配置里，有几个虚拟主机在不同的地址上监听：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen      192.168.1.1:80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      192.168.1.1:80;
    server_name example.net www.example.net;
    ...
}

server {
    listen      192.168.1.2:80;
    server_name example.com www.example.com;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这个配置中，nginx首先测试请求的IP地址和端口是否匹配某个server配置块中的listen指令配置。
接着nginx继续测试请求的Host头是否匹配这个server块中的某个server_name的值。 如果主机名没有找到，nginx将把这个请求交给默认虚拟主机处理。
例如，一个从192.168.1.1:80端口收到的访问www.example.com的请求将被监听192.168.1.1:80端口的默认虚拟主机处理，本例中就是第一个服务器，因为这个端口上没有定义名为www.example.com的虚拟主机。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;默认服务器是监听端口的属性&lt;/code&gt;，所以不同的监听端口可以设置不同的默认服务器：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen      192.168.1.1:80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      192.168.1.1:80 default_server;
    server_name example.net www.example.net;
    ...
}

server {
    listen      192.168.1.2:80 default_server;
    server_name example.com www.example.com;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;一个简单php站点配置&quot;&gt;一个简单PHP站点配置&lt;/h2&gt;
&lt;p&gt;现在我们来看在一个典型的，简单的PHP站点中，nginx怎样为一个请求选择location来处理：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen      80;
    server_name example.org www.example.org;
    root        /data/www;

    location / {
        index   index.html index.php;
    }

    location ~* \.(gif|jpg|png)$ {
        expires 30d;
    }

    location ~ \.php$ {
        fastcgi_pass  localhost:9000;
        fastcgi_param SCRIPT_FILENAME
                      $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;首先，nginx使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;前缀匹配&lt;/code&gt;找出最准确的location，这一步nginx会忽略location在配置文件出现的顺序。
上面的配置中，唯一的前缀匹配location是”/”，而且因为它可以匹配任意的请求，所以被作为最后一个选择。
接着，nginx继续按照配置中的顺序依次匹配正则表达式的location，匹配到第一个正则表达式后停止搜索，匹配到的location将被使用。
如果没有匹配到正则表达式的location，则使用刚刚找到的最准确的前缀匹配的location。&lt;/p&gt;

&lt;p&gt;请注意所有location匹配测试&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;只使用请求的URI部分，而不使用参数部分&lt;/code&gt;。这是因为写参数的方法很多，比如：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/index.php?user=john&amp;amp;page=1
/index.php?page=1&amp;amp;user=john
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;除此以外，任何人在请求串中都可以随意添加字符串：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/index.php?page=1&amp;amp;something+else&amp;amp;user=john
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;现在让我们来看使用上面的配置，请求是怎样被处理的：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;请求”/logo.gif”。
首先匹配上location “/”，然后匹配上正则表达式”.(gif|jpg|png)$”。
因此，它将被后者处理。根据”root /data/www”指令，nginx将请求映射到文件/data/www/logo.gif”，并发送这个文件到客户端。&lt;/li&gt;
  &lt;li&gt;请求”/index.php”。
首先也匹配上location “/”，然后匹配上正则表达式”.(php)$“。
因此，它将被后者处理，进而被发送到监听在localhost:9000的FastCGI服务器。
fastcgi_param指令将FastCGI的参数SCRIPT_FILENAME的值设置为”/data/www/index.php”，接着FastCGI服务器执行这个文件。
变量$document_root等于root指令设置的值，变量$fastcgi_script_name的值是请求的uri，”/index.php”。&lt;/li&gt;
  &lt;li&gt;请求”/about.html”。
仅能匹配上location “/”，因此，它将使用此location进行处理。
根据”root /data/www”指令，nginx将请求映射到文件”/data/www/about.html”，并发送这个文件到客户端。&lt;/li&gt;
  &lt;li&gt;请求”/”的处理更为复杂。它仅能匹配上location “/”，因此，它将使用此location进行处理。
然后，index指令使用它的参数和”root /data/www”指令所组成的文件路径来检测对应的文件是否存在。
如果文件/data/www/index.html不存在，而/data/www/index.php存在，此指令将执行一次内部重定向到”/index.php”，
接着nginx将重新寻找匹配”/index.php”的location，就好像这次请求是从客户端发过来一样。
正如我们之前看到的那样，这个重定向的请求最终交给FastCGI服务器来处理。&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/how-nginx-processes-a-request/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/how-nginx-processes-a-request/</guid>
      </item>
    
      <item>
        <title>调试日志</title>
        <description>&lt;p&gt;要开启调试日志，首先需要在配置nginx时&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;打开调试功能&lt;/code&gt;，然后编译：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./configure --with-debug ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;然后在配置文件中设置error_log的级别为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debug&lt;/code&gt;：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error_log  /path/to/log  debug;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;nginx的windows二进制版本总是将调试日志开启的，因此只需要设置debug的日志级别即可。&lt;/p&gt;

&lt;p&gt;注意，&lt;strong&gt;重新定义错误日志时，如过没有指定debug级别，调试日志会被屏蔽&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;下面的例子里，在server层中重新定义的日志就屏蔽了这个虚拟主机的调试日志：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error_log  /path/to/log  debug;
http {
    server {
        error_log  /path/to/log;
        ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;为了避免这个问题，注释这行重新定义日志的配置，或者也给日志指定debug级别：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error_log  /path/to/log  debug;
http {
    server {
        error_log  /path/to/log  debug;
        ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;另外，也可以只针对选定的客户端地址开启调试日志：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error_log  /path/to/log;
events {
    debug_connection   192.168.1.1;
    debug_connection   192.168.10.0/24;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/debugging-log/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/debugging-log/</guid>
      </item>
    
      <item>
        <title>转换rewrite规则</title>
        <description>&lt;h2 id=&quot;重定向到主站&quot;&gt;重定向到主站&lt;/h2&gt;
&lt;p&gt;共享站点的管理员，习惯于只在Apache下使用.htaccess文件配置所有信息，通常会将下面规则&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RewriteCond  %{HTTP_HOST}  example.org
RewriteRule  (.*)          http://www.example.org$1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;翻译成nginx配置是这样：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  www.example.org  example.org;
    if ($http_host = example.org) {
        rewrite  (.*)  http://www.example.org$1;
    }
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这种做法是错的，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;复杂而且低效&lt;/code&gt;。正确的方式是为example.org定义一个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;单独的服务器&lt;/code&gt;：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  example.org;
    return       301 http://www.example.org$request_uri;
}

server {
    listen       80;
    server_name  www.example.org;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在0.9.1版本（含）以前，可以这样实现重定向：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rewrite      ^ http://www.example.org$request_uri?;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;再举一个例子，处理一个和刚才相反的逻辑：既不是来自example.com，又不是来自www.example.com：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RewriteCond  %{HTTP_HOST}  !example.com
RewriteCond  %{HTTP_HOST}  !www.example.com
RewriteRule  (.*)          http://www.example.com$1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;应该按下面这样分开定义example.com、www.example.com和其他站点：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;server {
    listen       80;
    server_name  example.com www.example.com;
    ...
}

server {
    listen       80 default_server;
    server_name  _;
    return       301 http://example.com$request_uri;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在0.9.1版本（含）以前，可以这样实现重定向：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rewrite      ^ http://example.com$request_uri?;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;转化混合规则&quot;&gt;转化混合规则&lt;/h2&gt;

&lt;p&gt;典型的混合规则如下：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;DocumentRoot /var/www/myapp.com/current/public

RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [QSA,L]

RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]

RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;转换成nginx配置应该是这样：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;location / {
    root       /var/www/myapp.com/current/public;

    try_files  /system/maintenance.html
               $uri  $uri/index.html $uri.html
               @mongrel;
}

location @mongrel {
    proxy_pass  http://mongrel;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/converting-rewrite-rules/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/converting-rewrite-rules/</guid>
      </item>
    
      <item>
        <title>源码安装Nginx</title>
        <description>&lt;p&gt;使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;configure&lt;/code&gt;命令进行创建。它最后会创建makefile文件。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;configure命令&lt;/code&gt;支持如下参数：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–prefix=path - Nginx的安装根目录。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;该路径用于configure命令和nginx.conf中配置的所有相对路径。默认路径为/usr/local/nginx。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–sbin-path=path - Nginx可执行文件名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;仅用于安装时，默认是prefix/sbin/nginx。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–conf-path=path - nginx.conf配置文件名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c选项&lt;/code&gt;可以用于指定nginx启动时的配置文件。默认是prefix/conf/nginx.conf。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–pid-path=path - nginx pid文件名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;安装完成后可以通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pid指令&lt;/code&gt;在nginx.conf中配置。默认为prefix/logs/nginx.pid。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–error-log-path=path - 错误、警告和诊断信息文件名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;安装完成后可以通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error_log指令&lt;/code&gt;在nginx.conf中配置。默认是prefix/logs/error.log。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–http-log-path=path - HTTP服务器的请求日志文件名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;安装完成后可以通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;access_log指令&lt;/code&gt;在nginx.conf中配置。默认是prefix/logs/access.log。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–user=name - 设置未授权用户名。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;工作进程会使用其证书。安装完成后可以通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user指令&lt;/code&gt;在nginx.conf中配置。默认是nobody。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–group=name - 设置组的名字。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;具体用法同–user。默认也是nobody。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–with-select_module/–without-select_module - 使用select module处理事件驱动。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如果系统不支持其他方法如kqueue、epoll、rtsig、/dev/poll等，自动使用该选项。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;–with-poll_module/–without-poll_module - 用法同select。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;–without-http_gzip_module - 不安装http gzip module。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;根据配置文件中指定的content-type压缩HTTP的响应包。需要zlib库的支持。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–without-http_rewrite_module - 不安装http rewrite module。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;该模块提供HTTP请求在nginx服务内部的重定向功能，依赖PCRE库。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–without-http_proxy_module - 不安装http proxy module。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;该模块提供基本的HTTP反向代理功能。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–with-http_ssl_module - 安装http ssl module。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;该模块是nginx支持ssl协议，提供HTTPS服务，依赖OpenSSL库。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–with-pcre=path - 指定PCRE源码目录。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;使用PCRE库解析配置文件中location的正则表达式。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;–with-pcre-jit - 编译带jit的PCRE库。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;–with-zlib=path - 指定zlib库的源码目录。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;如果使用了gzip压缩功能，需要zlib库的支持。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–with-cc-opt=parameters - 设置额外参数到CFLAGS变量中。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;例如，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--with-cc-opt=&quot;-D FD_SETSIZE=2048&quot;&lt;/code&gt;，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--with-cc-opt=&quot;-I /usr/local/include&quot;&lt;/code&gt;。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;–with-ld-opt=parameters - 链接阶段设置额外参数。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;例如，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--with-ld-opt=&quot;-L /usr/local/lib&quot;&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;使用示例&lt;/strong&gt;：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./configure
    --sbin-path=/usr/local/nginx/nginx
    --conf-path=/usr/local/nginx/nginx.conf
    --pid-path=/usr/local/nginx/nginx.pid
    --with-http_ssl_module
    --with-pcre=../pcre-4.4
    --with-zlib=../zlib-1.1.3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/ngx-docs/building-nginx-from-sources/</link>
        <guid isPermaLink="true">https://yanl.cc/ngx-docs/building-nginx-from-sources/</guid>
      </item>
    
      <item>
        <title>Love you always</title>
        <description>&lt;p&gt;“草在结它的种子 风在摇它的叶子 我们站着 不说话 就十分美好。” — 顾城&lt;/p&gt;

&lt;iframe width=&quot;100%&quot; height=&quot;100%&quot; src=&quot;https://yanl.cc/images/post/nene.mp4&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
</description>
        <pubDate>Thu, 18 Oct 2018 00:00:00 +0800</pubDate>
        <link>https://yanl.cc/life/2018/10/18/funny-video/</link>
        <guid isPermaLink="true">https://yanl.cc/life/2018/10/18/funny-video/</guid>
      </item>
    
  </channel>
</rss>
