配置例子

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. userid on;
  5. userid_name SESSIONID;
  6. userid_domain localhost;
  7. userid_path /;
  8. client_max_body_size 100k;
  9. hi_need_tokens off;
  10. hi_cache_method GET;
  11. hi_need_cache on;
  12. hi_cache_size 10;
  13. hi_cache_expires 300s;
  14. hi_need_kvdb off;
  15. hi_kvdb_size 10;
  16. hi_kvdb_expires 5m;
  17. hi_need_headers off;
  18. hi_need_cookies off;
  19. hi_need_session off;
  20. hi_session_expires 300s;
  21. hi_redis_host 127.0.0.1;
  22. hi_redis_port 6379;
  23. hi_java_classpath "-Djava.class.path=.:/usr/local/nginx/java:/usr/local/nginx/java/hi-nginx-java.jar";
  24. hi_java_options "-server -d64 -Xms512m -Xmx512m -Xmn170m";
  25. hi_java_servlet_cache_expires 300s;
  26. hi_java_servlet_cache_size 10;
  27. hi_java_version 8;
  28. hi_lua_package_path '/usr/local/nginx/lua/?.lua;';
  29. hi_lua_package_cpath '/usr/local/nginx/lua/?.so;';
  30. hi_duktape_package_path '/usr/local/nginx/duktape/package';
  31. hi_duktape_package_cpath '/usr/local/nginx/duktape/package';
  32. location ~ \.py$ {
  33. rewrite ^/(.*)\.py$ /$1 break;
  34. hi_python_script python/index.py;
  35. }
  36. location ~ \.lua$ {
  37. rewrite ^/(.*)\.lua$ /$1 break;
  38. hi_lua_script lua/index.lua;
  39. }
  40. location ~ \.duktape$ {
  41. rewrite ^/(.*)\.duktape$ /$1 break;
  42. hi_duktape_script duktape/index.js;
  43. }
  44. location ~ \.php$ {
  45. rewrite ^/(.*)\.php$ /$1 break;
  46. hi_php_script php/index.php;
  47. }
  48. location ~ \.jsp$ {
  49. rewrite ^/(.*)\.jsp$ /$1 break;
  50. hi_java_servlet_cache_expires 60s;
  51. hi_java_servlet hi/index;
  52. }
  53. location ~ \.do$ {
  54. rewrite ^/(.*)\.do$ /$1 break;
  55. hi cpp/index.so;
  56. }
  57. location ^~ /sub {
  58. hi_subrequest '/query';
  59. hi_lua_content 'hi_res:header("Content-Type",hi_req:get_form("__subrequest_content_type__"))\nhi_res:status(tonumber(hi_req:get_form("__subrequest_status__")))\nhi_res:content(hi_req:get_form("__subrequest_body__"))';
  60. }
  61. location ^~ /query {
  62. internal;
  63. proxy_pass http://http://hq.sinajs.cn/;
  64. proxy_set_header Accept-Encoding '';
  65. }
  66. # curl -i http://localhost/sub?list=sh601006
  67. location / {
  68. hi_javascript_lang javascript;
  69. hi_javascript_extension js;
  70. hi_javascript_compiledscript_expires 5m;
  71. hi_javascript_script javascript/index.js;
  72. #hi_javascript_content "hi_res.content='hello,world';hi_res.status=200;";
  73. }
  74. }

特别说明

以上配置命令演示均使用相对路径。如果你按照配置启动后发现404错误,多半是你启动hi-nginx的方式使得相对路径无效。

这时,较差的建议是把配置改成绝对路径。较好的建议是只通过systemctl启动,从而确保启动目录正确、从而相对路径有效。

修改配置后,一定要systemctl reload nginx

感谢网友热情地提出增加关于使用相对路径的特别说明的建议。

原文: https://doc.hi-nginx.com/00/0002.html