5.1. 配置通览和说明

安装时复制的配置文件为缺省配置,可根据实际情况调整,如侦听端口、server配置等。

  1. $ cat ~/etc/hetao.conf
  2. {
  3. "worker_processes" : 1 ,
  4. "cpu_affinity" : 1 ,
  5. "accept_mutex" : 1 ,
  6.  
  7. "error_log" : "/var/hetao/log/error.log" ,
  8. "log_level" : ERROR ,
  9.  
  10. "user" : "nobody" ,
  11.  
  12. "limits" :
  13. {
  14. "max_http_session_count" : 100000 ,
  15. "max_file_cache" : 1024000 ,
  16. "max_connections_per_ip" : -1
  17. } ,
  18.  
  19. "listen" :
  20. {
  21. "ip" : "" ,
  22. "port" : 80 ,
  23. "website" :
  24. {
  25. "domain" : "" ,
  26. "wwwroot" : "/var/hetao/www" ,
  27. "index" : "/index.html,/index.htm" ,
  28. "access_log" : "/var/hetao/log/access.log"
  29. }
  30. } ,
  31.  
  32. /*
  33. "listen" :
  34. {
  35. "ip" : "" ,
  36. "port" : 80 ,
  37. "website" :
  38. {
  39. "domain" : "www.test.com" ,
  40. "wwwroot" : "/var/hetao/www.test.com" ,
  41. "index" : "/index.html,/index.htm" ,
  42. "access_log" : "/var/hetao/log/www_test_com_access.log"
  43. } ,
  44. "website" :
  45. {
  46. "domain" : "www.test2.com" ,
  47. "wwwroot" : "/var/hetao/www.test2.com" ,
  48. "index" : "/index.html,/index.htm" ,
  49. "access_log" : "/var/hetao/log/www_test2_com_access.log"
  50. }
  51. } ,
  52. */
  53.  
  54. /*
  55. "listen" :
  56. {
  57. "ip" : "" ,
  58. "port" : 80 ,
  59. "website" :
  60. {
  61. "domain" : "" ,
  62. "wwwroot" : "/var/hetao/www" ,
  63. "index" : "/index.html,/index.htm" ,
  64. "access_log" : "/var/hetao/log/access.log" ,
  65. "rewrite" : { "pattern":"/(.+)/(.+)" , "new_uri":"/(2)/(1)" }
  66. }
  67. } ,
  68. */
  69.  
  70. /*
  71. "listen" :
  72. {
  73. "ip" : "" ,
  74. "port" : 80 ,
  75. "website" :
  76. {
  77. "domain" : "" ,
  78. "wwwroot" : "/var/hetao/www" ,
  79. "index" : "/index.html,/index.htm" ,
  80. "access_log" : "/var/hetao/log/access.log" ,
  81. "forward" :
  82. {
  83. "forward_type" : "php" ,
  84. "forward_rule" : "R" ,
  85. "forward_server" : { "ip" : "192.168.6.17" , "port" : 8601 } ,
  86. "forward_server" : { "ip" : "192.168.6.17" , "port" : 8602 } ,
  87. "forward_server" : { "ip" : "192.168.6.17" , "port" : 8603 } ,
  88. "forward_server" : { "ip" : "192.168.6.17" , "port" : 8604 } ,
  89. "forward_server" : { "ip" : "192.168.6.17" , "port" : 8605 }
  90. } ,
  91. "socgi" :
  92. {
  93. // "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_hello.socgi"
  94. // "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_rest_hello.socgi"
  95. "socgi_type" : "" , "socgi_pathfilename" : "www/test_socgi_rest_full.socgi"
  96. }
  97. }
  98. } ,
  99. */
  100.  
  101. /*
  102. "listen" :
  103. {
  104. "ip" : "" ,
  105. "port" : 80 ,
  106. "website" :
  107. {
  108. "domain" : "" ,
  109. "wwwroot" : "/var/hetao/www" ,
  110. "index" : "/index.html,/index.htm" ,
  111. "access_log" : "/var/hetao/log/access.log" ,
  112. "forward" :
  113. {
  114. "forward_type" : "php" ,
  115. "forward_rule" : "R" ,
  116. "ssl" :
  117. {
  118. "certificate_file" : "/etc/hetao/certs/server.crt"
  119. } ,
  120. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
  121. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
  122. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 }
  123. }
  124. }
  125. } ,
  126. */
  127.  
  128. /*
  129. "listen" :
  130. {
  131. "ip" : "" ,
  132. "port" : 443 ,
  133. "ssl" :
  134. {
  135. "certificate_file" : "/etc/hetao/certs/server.pem" ,
  136. "certificate_key_file" : "/etc/hetao/certs/server.key"
  137. } ,
  138. "website" :
  139. {
  140. "domain" : "" ,
  141. "wwwroot" : "/var/hetao/www" ,
  142. "index" : "/index.html,/index.htm" ,
  143. "access_log" : "/var/hetao/log/access.log"
  144. }
  145. } ,
  146. */
  147.  
  148. "tcp_options" :
  149. {
  150. "nodelay" : 1 ,
  151. "nolinger" : -1
  152. } ,
  153.  
  154. "http_options" :
  155. {
  156. "compress_on" : 1 ,
  157. "timeout" : 30 ,
  158. "elapse" : 60 ,
  159. "forward_disable" : 60
  160. } ,
  161.  
  162. "error_pages" :
  163. {
  164. "error_page_400" : "/var/hetao/www/error_pages/error_page_400.html" ,
  165. "error_page_401" : "/var/hetao/www/error_pages/error_page_401.html" ,
  166. "error_page_403" : "/var/hetao/www/error_pages/error_page_403.html" ,
  167. "error_page_404" : "/var/hetao/www/error_pages/error_page_404.html" ,
  168. "error_page_408" : "/var/hetao/www/error_pages/error_page_408.html" ,
  169. "error_page_500" : "/var/hetao/www/error_pages/error_page_500.html" ,
  170. "error_page_503" : "/var/hetao/www/error_pages/error_page_503.html" ,
  171. "error_page_505" : "/var/hetao/www/error_pages/error_page_505.html"
  172. } ,
  173.  
  174. "mime_types" :
  175. {
  176. "mime_type" : { "type":"html htm shtml" , "mime":"text/html" , "compress_enable":1 } ,
  177. "mime_type" : { "type":"css" , "mime":"text/css" , "compress_enable":0 } ,
  178. "mime_type" : { "type":"xml" , "mime":"text/xml" , "compress_enable":1 } ,
  179. "mime_type" : { "type":"txt" , "mime":"text/plain" , "compress_enable":1 } ,
  180. "mime_type" : { "type":"gif" , "mime":"image/gif" } ,
  181. "mime_type" : { "type":"jpeg jpg" , "mime":"image/jpeg" } ,
  182. "mime_type" : { "type":"png" , "mime":"image/png" } ,
  183. "mime_type" : { "type":"tif tiff" , "mime":"image/tiff" } ,
  184. "mime_type" : { "type":"ico" , "mime":"image/x-ico" } ,
  185. "mime_type" : { "type":"jng" , "mime":"image/x-jng" } ,
  186. "mime_type" : { "type":"bmp" , "mime":"image/x-ms-bmp" } ,
  187. "mime_type" : { "type":"svg svgz" , "mime":"image/svg+xml" , "compress_enable":1 } ,
  188. "mime_type" : { "type":"jar war ear" , "mime":"application/java-archive" } ,
  189. "mime_type" : { "type":"json" , "mime":"application/json" , "compress_enable":1 } ,
  190. "mime_type" : { "type":"doc" , "mime":"application/msword" } ,
  191. "mime_type" : { "type":"pdf" , "mime":"application/pdf" } ,
  192. "mime_type" : { "type":"rtf" , "mime":"application/rtf" } ,
  193. "mime_type" : { "type":"xls" , "mime":"application/vnd.ms-excel" } ,
  194. "mime_type" : { "type":"ppt" , "mime":"application/vnd.ms-powerpoint" } ,
  195. "mime_type" : { "type":"7z" , "mime":"application/x-7z-compressed" } ,
  196. "mime_type" : { "type":"rar" , "mime":"application/x-rar-compressed" } ,
  197. "mime_type" : { "type":"swf" , "mime":"application/x-shockwave-flash" } ,
  198. "mime_type" : { "type":"xhtml" , "mime":"application/xhtml+xml" , "compress_enable":1 } ,
  199. "mime_type" : { "type":"bin exe dll iso img msi msp msm" , "mime":"application/octet-stream" } ,
  200. "mime_type" : { "type":"zip" , "mime":"application/zip" } ,
  201. "mime_type" : { "type":"docx" , "mime":"application/vnd.openxmlformats-officedocument.wordprocessingml.document" } ,
  202. "mime_type" : { "type":"xlsx" , "mime":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } ,
  203. "mime_type" : { "type":"pptx" , "mime":"application/vnd.openxmlformats-officedocument.presentationml.presentation" } ,
  204. "mime_type" : { "type":"mid midi kar" , "mime":"audio/midi" } ,
  205. "mime_type" : { "type":"mp3" , "mime":"audio/mpeg" } ,
  206. "mime_type" : { "type":"ogg" , "mime":"audio/ogg" } ,
  207. "mime_type" : { "type":"m4a" , "mime":"audio/x-m4a" } ,
  208. "mime_type" : { "type":"ra" , "mime":"audio/x-realaudio" } ,
  209. "mime_type" : { "type":"3gpp 3gp" , "mime":"video/3gpp" } ,
  210. "mime_type" : { "type":"ts" , "mime":"video/mp2t" } ,
  211. "mime_type" : { "type":"mp4" , "mime":"video/mp4" } ,
  212. "mime_type" : { "type":"mpeg mpg" , "mime":"video/mpeg" } ,
  213. "mime_type" : { "type":"mov" , "mime":"video/quicktime" } ,
  214. "mime_type" : { "type":"webm" , "mime":"video/webm" } ,
  215. "mime_type" : { "type":"flv" , "mime":"video/x-flv" } ,
  216. "mime_type" : { "type":"m4v" , "mime":"video/x-m4v" } ,
  217. "mime_type" : { "type":"mng" , "mime":"video/x-mng" } ,
  218. "mime_type" : { "type":"asx asf" , "mime":"video/x-ms-asf" } ,
  219. "mime_type" : { "type":"wmv" , "mime":"video/x-ms-wmv" } ,
  220. "mime_type" : { "type":"avi" , "mime":"video/x-msvideo" }
  221. }
  222. }
配置项说明
workerprocessesLinux环境里启动的工作进程数量,如果为-1则设置为CPU核数量;缺省值为1
cpu_affinity如果为1,则子进程绑定在CPU上,如果为0,不绑定;缺省值为1
accept_mutex如果为1,开启accept锁,防止多子进程因epoll惊群而引起的CPU稍稍高耗;缺省值为0
error_log详细日志文件名。支持$…$环境变量展开。以下所有目录文件配置项都可以内嵌环境变量;缺省值为空
log_level详细日志文件内的日志等级,枚举有DEBUG、INFO、WARN、ERROR、FATAL;缺省值为ERROR
user启动后以该用户身份(可选配置);缺省值为"nobody"
limits限制设置
- max_http_session_count最大HTTP通讯会话并发数量;缺省值为100000
- max_file_cache最大缓存文件大小;缺省值为1024000
- max_connections_per_ip每个IP最大连接数限制,-1为不限制;缺省值为-1
- headers_count_hardmaxHTTP请求最大头数量;缺省值为128
- headers_len_hardmaxHTTP请求最大头选项大小;缺省值为4KB
- header_content_length_val_hardmaxHTTP请求最大体大小;缺省值为4MB
listen网络侦听地址
- ip本地侦听端口,填空则为0.0.0.0
- port本地侦听端口
- ssl服务端安全加密规则(可选配置块)
- - certificate_file公钥证书文件名
- - certificate_key_file私钥文件名
- website []网站配置;一个网路侦听地址里可以运行多个网站
- - domain网站域名,用于匹配HTTP请求头选项Host区分虚拟主机。如果填空则统配所有
- - wwwroot网站本地根目录
- - index当浏览器请求的是目录,尝试的入口文件,格式为"/index.html",如果有多个,则格式为"/index.html,/index.htm,…"。注意:入口文件名前有"/"
- - access_log事件日志文件名,一个HTTP请求写一条事件日志
- - rewrite改写URI规则(可选配置块)
- - - pattern原URI正则匹配式,如"/(.+)/(.+)"
- - - new_uri新URI格式,如"/(2)/(1)"
- - forward反向代理规则(可选配置块)
- - - forward_type该文件扩展名的URL走反向代理
- - - forward_rule负载均衡算法,目前支持:R轮询,L最少连接数
- - - ssl客户端安全加密规则(可选配置块)
- - - certificate_file公钥证书文件名
- - - forward_server []后端应用服务器地址
- - - - ip后端侦听端口
- - - - port后端侦听端口
tcp_optionsTCP选项(可选配置块)
- nodelay当为1时,启用TCP选项TCP_NODELAY,有助于提高响应速度;当为0时,关闭之;缺省值为1
- nolinger当大于等于0时,启用TCP选项SO_LINGER并设置成其值;当为-1时,不设置之;缺省值为-1
http_optionsHTTP选项(可选配置块)
- compress_on是否响应浏览器端的压缩请求,有助于大幅减少通讯传输流量;缺省值为1
- timeoutHTTP活跃超时时间,单位:秒;缺省值为30
- elapseHTTP累积超时时间,单位:秒;缺省值为60
- forward_disable当反向代理连接后端失败后,暂禁时间,单位:秒;缺省值为60
error_pages出错页面配置(可选配置块)
- error_page???HTTP响应???时返回的页面文件,目前支持400、401、403、404、408、500、503、505
mime_types流类型配置集合。主要用于填充HTTP响应头选项Content-Type;缺省值为缺省配置文件中信息
- mime_type []流类型配置
- - type文件扩展名
- - mime流类型描述,填充HTTP响应头选项Content-Type
- - compress_enable是否压缩缓存,1位压缩,不出现或0为不压缩

最后注意:json元素之间有","以及最后一个元素后面没有","。