5.3. 网站配置和示例
网站配置层次关系:
- listen(侦听) - website(网站) - forward_server(反向代理转发服务器)
一个hetao运行实例里可以有多个listen,每个listen为一个ip、port对,对应一个TCP服务端侦听。每个listen上可以配置多个网站website,基于域名domain识别虚拟主机。每个website上可以配置成某一文件类型forward_type转发到后方应用服务器forward_server,以及负载均衡算法forward_rule。
domain需要匹配浏览器访问Web服务器请求头选项Host的值(URL中"http://"与"/"之间的部分)以确定服务器使用哪个虚拟主机来响应,如:
- http://www.google.com/ domain为"www.google.com"
- http://192.168.1.110:8080/ domain为"192.168.1.110:8080"
5.3.1. 简单的网站配置
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log"
- }
- } ,
5.3.2. 带域名的虚拟主机网站配置(两个虚拟主机)
- "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"
- } ,
- {
- "domain" : "www.test2.com" ,
- "wwwroot" : "/var/hetao/www.test2.com" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/www_test_com_access.log"
- }
- } ,
5.3.3. 需要改写URI的网站配置(/xxx/yyy改写为/yyy/xxx)
- "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)" }
- }
- } ,
5.3.4. 需要重定向域名的网站配置(www.google.com改写为www.baidu.com)
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log" ,
- "redirect" : { "domain":"www.google.com" , "new_domain":"http://www.baidu.com" }
- }
- } ,
5.3.5. 简单的HTTPS网站配置
- "listen" :
- {
- "ip" : "" ,
- "port" : 443 ,
- "website" :
- {
- "domain" : "" ,
- "wwwroot" : "/var/hetao/www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "/var/hetao/log/access.log" ,
- "ssl" :
- {
- "certificate_file" : "/etc/hetao/certs/server.pem" ,
- "certificate_key_file" : "/etc/hetao/certs/server.key"
- }
- }
- } ,
5.3.6. 反向代理配置,针对文件类型php,轮询算法
- "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.111" , "port" : 8081 } ,
- "forward_server" : { "ip" : "192.168.6.111" , "port" : 8082 } ,
- "forward_server" : { "ip" : "192.168.6.111" , "port" : 8083 }
- }
- }
- } ,
5.3.7. 反向代理配置,针对文件类型php,轮询算法,转发时装载证书变成HTTPS
- "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 }
- }
- }
- } ,
5.3.8. SOCGI
URI扩展名为“.do”的HTTP请求,调用应用动态库
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "localhost" ,
- "wwwroot" : "www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "log/access.log" ,
- "socgi" :
- {
- "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_hello.socgi"
- }
- }
- }
RESTful风格应用的URI一般没有扩展名
- "listen" :
- {
- "ip" : "" ,
- "port" : 80 ,
- "website" :
- {
- "domain" : "localhost" ,
- "wwwroot" : "www" ,
- "index" : "/index.html,/index.htm" ,
- "access_log" : "log/access.log" ,
- "socgi" :
- {
- "socgi_type" : "" , "socgi_pathfilename" : "www/test_socgi_rest_full.socgi"
- }
- }
- }