5.3. 网站配置和示例

网站配置层次关系:

  1. 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://"与"/"之间的部分)以确定服务器使用哪个虚拟主机来响应,如:

  1. http://www.google.com/ domain为"www.google.com"
  2. http://192.168.1.110:8080/ domain为"192.168.1.110:8080"

5.3.1. 简单的网站配置

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log"
  11. }
  12. } ,

5.3.2. 带域名的虚拟主机网站配置(两个虚拟主机)

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "www.test.com" ,
  8. "wwwroot" : "/var/hetao/www.test.com" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/www_test_com_access.log"
  11. } ,
  12. {
  13. "domain" : "www.test2.com" ,
  14. "wwwroot" : "/var/hetao/www.test2.com" ,
  15. "index" : "/index.html,/index.htm" ,
  16. "access_log" : "/var/hetao/log/www_test_com_access.log"
  17. }
  18. } ,

5.3.3. 需要改写URI的网站配置(/xxx/yyy改写为/yyy/xxx)

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log" ,
  11. "rewrite" : { "pattern":"/(.+)/(.+)" , "new_uri":"/(2)/(1)" }
  12. }
  13. } ,

5.3.4. 需要重定向域名的网站配置(www.google.com改写为www.baidu.com)

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log" ,
  11. "redirect" : { "domain":"www.google.com" , "new_domain":"http://www.baidu.com" }
  12. }
  13. } ,

5.3.5. 简单的HTTPS网站配置

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 443 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log" ,
  11. "ssl" :
  12. {
  13. "certificate_file" : "/etc/hetao/certs/server.pem" ,
  14. "certificate_key_file" : "/etc/hetao/certs/server.key"
  15. }
  16. }
  17. } ,

5.3.6. 反向代理配置,针对文件类型php,轮询算法

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log" ,
  11. "forward" :
  12. {
  13. "forward_type" : "php" ,
  14. "forward_rule" : "R" ,
  15. "forward_server" : { "ip" : "192.168.6.111" , "port" : 8081 } ,
  16. "forward_server" : { "ip" : "192.168.6.111" , "port" : 8082 } ,
  17. "forward_server" : { "ip" : "192.168.6.111" , "port" : 8083 }
  18. }
  19. }
  20. } ,

5.3.7. 反向代理配置,针对文件类型php,轮询算法,转发时装载证书变成HTTPS

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "" ,
  8. "wwwroot" : "/var/hetao/www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "/var/hetao/log/access.log" ,
  11. "forward" :
  12. {
  13. "forward_type" : "php" ,
  14. "forward_rule" : "R" ,
  15. "ssl" :
  16. {
  17. "certificate_file" : "/etc/hetao/certs/server.crt"
  18. } ,
  19. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
  20. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 } ,
  21. "forward_server" : { "ip" : "192.168.6.111" , "port" : 1443 }
  22. }
  23. }
  24. } ,

5.3.8. SOCGI

URI扩展名为“.do”的HTTP请求,调用应用动态库

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "localhost" ,
  8. "wwwroot" : "www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "log/access.log" ,
  11. "socgi" :
  12. {
  13. "socgi_type" : "do" , "socgi_pathfilename" : "www/test_socgi_hello.socgi"
  14. }
  15. }
  16. }

RESTful风格应用的URI一般没有扩展名

  1. "listen" :
  2. {
  3. "ip" : "" ,
  4. "port" : 80 ,
  5. "website" :
  6. {
  7. "domain" : "localhost" ,
  8. "wwwroot" : "www" ,
  9. "index" : "/index.html,/index.htm" ,
  10. "access_log" : "log/access.log" ,
  11. "socgi" :
  12. {
  13. "socgi_type" : "" , "socgi_pathfilename" : "www/test_socgi_rest_full.socgi"
  14. }
  15. }
  16. }