5.1. 配置通览和说明
安装时复制的配置文件为缺省配置,可根据实际情况调整,如侦听端口、server配置等。
- $ cat ~/etc/hetao.conf
- {
- "worker_processes" : 1 ,
- "cpu_affinity" : 1 ,
- "accept_mutex" : 1 ,
- "error_log" : "/var/hetao/log/error.log" ,
- "log_level" : ERROR ,
- "user" : "nobody" ,
- "limits" :
- {
- "max_http_session_count" : 100000 ,
- "max_file_cache" : 1024000 ,
- "max_connections_per_ip" : -1
- } ,
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log"
- }
- } ,
- /*
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "www.test.com" ,
- "wwwroot" : "/var/hetao/www.test.com" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/www_test_com_access.log"
- } ,
- "website" :
- {
- "domain" : "www.test2.com" ,
- "wwwroot" : "/var/hetao/www.test2.com" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/www_test2_com_access.log"
- }
- } ,
- */
- /*
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log" ,
- "rewrite" : { "pattern":"/(.+)/(.+)" , "new_uri":"/(2)/(1)" }
- }
- } ,
- */
- /*
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log" ,
- "forward" :
- {
- "forward_type" : "php" ,
- "forward_rule" : "R" ,
- "forward_server" : { "ip" : "192.168.6.17" , "port" : 8601 } ,
- "forward_server" : { "ip" : "192.168.6.17" , "port" : 8602 } ,
- "forward_server" : { "ip" : "192.168.6.17" , "port" : 8603 } ,
- "forward_server" : { "ip" : "192.168.6.17" , "port" : 8604 } ,
- "forward_server" : { "ip" : "192.168.6.17" , "port" : 8605 }
- } ,
- "socgi" :
- {
- // "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_hello.socgi"
- // "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_rest_hello.socgi"
- "socgi_type" : "" , "socgi_pathfilename" : "www/test_socgi_rest_full.socgi"
- }
- }
- } ,
- */
- /*
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log" ,
- "forward" :
- {
- "forward_type" : "php" ,
- "forward_rule" : "R" ,
- "ssl" :
- {
- "certificate_file" : "/etc/hetao/certs/server.crt"
- } ,
- "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
- "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
- "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 }
- }
- }
- } ,
- */
- /*
- "listen" :
- {
- "ip" : "" ,
- "port" : 443 ,
- "ssl" :
- {
- "certificate_file" : "/etc/hetao/certs/server.pem" ,
- "certificate_key_file" : "/etc/hetao/certs/server.key"
- } ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log"
- }
- } ,
- */
- "tcp_options" :
- {
- "nodelay" : 1 ,
- "nolinger" : -1
- } ,
- "http_options" :
- {
- "compress_on" : 1 ,
- "timeout" : 30 ,
- "elapse" : 60 ,
- "forward_disable" : 60
- } ,
- "error_pages" :
- {
- "error_page_400" : "/var/hetao/www/error_pages/error_page_400.html" ,
- "error_page_401" : "/var/hetao/www/error_pages/error_page_401.html" ,
- "error_page_403" : "/var/hetao/www/error_pages/error_page_403.html" ,
- "error_page_404" : "/var/hetao/www/error_pages/error_page_404.html" ,
- "error_page_408" : "/var/hetao/www/error_pages/error_page_408.html" ,
- "error_page_500" : "/var/hetao/www/error_pages/error_page_500.html" ,
- "error_page_503" : "/var/hetao/www/error_pages/error_page_503.html" ,
- "error_page_505" : "/var/hetao/www/error_pages/error_page_505.html"
- } ,
- "mime_types" :
- {
- "mime_type" : { "type":"html htm shtml" , "mime":"text/html" , "compress_enable":1 } ,
- "mime_type" : { "type":"css" , "mime":"text/css" , "compress_enable":0 } ,
- "mime_type" : { "type":"xml" , "mime":"text/xml" , "compress_enable":1 } ,
- "mime_type" : { "type":"txt" , "mime":"text/plain" , "compress_enable":1 } ,
- "mime_type" : { "type":"gif" , "mime":"image/gif" } ,
- "mime_type" : { "type":"jpeg jpg" , "mime":"image/jpeg" } ,
- "mime_type" : { "type":"png" , "mime":"image/png" } ,
- "mime_type" : { "type":"tif tiff" , "mime":"image/tiff" } ,
- "mime_type" : { "type":"ico" , "mime":"image/x-ico" } ,
- "mime_type" : { "type":"jng" , "mime":"image/x-jng" } ,
- "mime_type" : { "type":"bmp" , "mime":"image/x-ms-bmp" } ,
- "mime_type" : { "type":"svg svgz" , "mime":"image/svg+xml" , "compress_enable":1 } ,
- "mime_type" : { "type":"jar war ear" , "mime":"application/java-archive" } ,
- "mime_type" : { "type":"json" , "mime":"application/json" , "compress_enable":1 } ,
- "mime_type" : { "type":"doc" , "mime":"application/msword" } ,
- "mime_type" : { "type":"pdf" , "mime":"application/pdf" } ,
- "mime_type" : { "type":"rtf" , "mime":"application/rtf" } ,
- "mime_type" : { "type":"xls" , "mime":"application/vnd.ms-excel" } ,
- "mime_type" : { "type":"ppt" , "mime":"application/vnd.ms-powerpoint" } ,
- "mime_type" : { "type":"7z" , "mime":"application/x-7z-compressed" } ,
- "mime_type" : { "type":"rar" , "mime":"application/x-rar-compressed" } ,
- "mime_type" : { "type":"swf" , "mime":"application/x-shockwave-flash" } ,
- "mime_type" : { "type":"xhtml" , "mime":"application/xhtml+xml" , "compress_enable":1 } ,
- "mime_type" : { "type":"bin exe dll iso img msi msp msm" , "mime":"application/octet-stream" } ,
- "mime_type" : { "type":"zip" , "mime":"application/zip" } ,
- "mime_type" : { "type":"docx" , "mime":"application/vnd.openxmlformats-officedocument.wordprocessingml.document" } ,
- "mime_type" : { "type":"xlsx" , "mime":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" } ,
- "mime_type" : { "type":"pptx" , "mime":"application/vnd.openxmlformats-officedocument.presentationml.presentation" } ,
- "mime_type" : { "type":"mid midi kar" , "mime":"audio/midi" } ,
- "mime_type" : { "type":"mp3" , "mime":"audio/mpeg" } ,
- "mime_type" : { "type":"ogg" , "mime":"audio/ogg" } ,
- "mime_type" : { "type":"m4a" , "mime":"audio/x-m4a" } ,
- "mime_type" : { "type":"ra" , "mime":"audio/x-realaudio" } ,
- "mime_type" : { "type":"3gpp 3gp" , "mime":"video/3gpp" } ,
- "mime_type" : { "type":"ts" , "mime":"video/mp2t" } ,
- "mime_type" : { "type":"mp4" , "mime":"video/mp4" } ,
- "mime_type" : { "type":"mpeg mpg" , "mime":"video/mpeg" } ,
- "mime_type" : { "type":"mov" , "mime":"video/quicktime" } ,
- "mime_type" : { "type":"webm" , "mime":"video/webm" } ,
- "mime_type" : { "type":"flv" , "mime":"video/x-flv" } ,
- "mime_type" : { "type":"m4v" , "mime":"video/x-m4v" } ,
- "mime_type" : { "type":"mng" , "mime":"video/x-mng" } ,
- "mime_type" : { "type":"asx asf" , "mime":"video/x-ms-asf" } ,
- "mime_type" : { "type":"wmv" , "mime":"video/x-ms-wmv" } ,
- "mime_type" : { "type":"avi" , "mime":"video/x-msvideo" }
- }
- }
配置项 | 说明 |
---|---|
workerprocesses | Linux环境里启动的工作进程数量,如果为-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_hardmax | HTTP请求最大头数量;缺省值为128 |
- headers_len_hardmax | HTTP请求最大头选项大小;缺省值为4KB |
- header_content_length_val_hardmax | HTTP请求最大体大小;缺省值为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_options | TCP选项(可选配置块) |
- nodelay | 当为1时,启用TCP选项TCP_NODELAY,有助于提高响应速度;当为0时,关闭之;缺省值为1 |
- nolinger | 当大于等于0时,启用TCP选项SO_LINGER并设置成其值;当为-1时,不设置之;缺省值为-1 |
http_options | HTTP选项(可选配置块) |
- compress_on | 是否响应浏览器端的压缩请求,有助于大幅减少通讯传输流量;缺省值为1 |
- timeout | HTTP活跃超时时间,单位:秒;缺省值为30 |
- elapse | HTTP累积超时时间,单位:秒;缺省值为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元素之间有","以及最后一个元素后面没有","。