配置命令

  • directives : content: loc,if in loc

    • hi,default: ""

example:

  1. location = /hello {
  2. hi cpp/hello.so ;
  3. }
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_tokens,default: on

example:

  1. hi_need_tokens on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_cache_method,default: GET

example:

  1. hi_cache_method GET|POST|PUT|HEAD;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_cache,default: on

example:

  1. hi_need_cache on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_cache_size,default: 10

example:

  1. hi_cache_size 10;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_cache_expires,default: 300s

example:

  1. hi_cache_expires 300s;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_kvdb,default: off

example:

  1. hi_need_kvdb on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_kvdb_size,default: 10

example:

  1. hi_kvdb_size 10;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_kvdb_expires,default: 300s

example:

  1. hi_kvdb_expires 300s;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_headers,default: off

    example:

  1. hi_need_headers on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_cookies,default: off

    example:

  1. hi_need_cookies on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_need_session,default: off

    example:

  1. hi_need_session on|off;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_session_expires,default: 300s

example:

  1. hi_session_expires 300s;
  • directives : content: http,srv ,if in srv

    • hi_redis_host,default: ""

example:

  1. hi_redis_host 127.0.0.1;
  • directives : content: http,srv,if in srv

    • hi_redis_port,default: 0

example:

  1. hi_redis_port 6379;
  • directives : content: loc,if in loc

    • hi_python_content,default: ""

example:

  1. location = /pyecho {
  2. hi_python_content "hi_res.status(200)\nhi_res.content('hello,world')" ;
  3. }
  • directives : content: loc,if in loc

    • hi_python_script,default: ""

example:

  1. location ~ \.py$ {
  2. hi_python_script python;
  3. }

or

  1. location / {
  2. hi_python_script python/index.py;
  3. }
  • directives : content: http,srv,if in srv

    • hi_lua_package_path,default: ""

example:

  1. hi_lua_package_path '/usr/local/nginx/lua/?.lua;';
  • directives : content: http,srv,if in srv

    • hi_lua_package_cpath,default: ""

example:

  1. hi_lua_package_cpath '/usr/local/nginx/lua/?.so;';
  • directives : content: loc,if in loc

    • hi_lua_content,default: ""

example:

  1. location = /luaecho {
  2. hi_lua_content "hi_res:status(200)\nhi_res:content('hello,world')" ;
  3. }
  • directives : content: loc,if in loc

    • hi_lua_script,default: ""

example:

  1. location ~ \.lua$ {
  2. hi_lua_script lua;
  3. }

or

  1. location / {
  2. hi_lua_script lua/index.lua;
  3. }
  • directives : content: http,srv,if in srv

    • hi_duktape_package_path,default: ""

example:

  1. hi_duktape_package_path '/usr/local/nginx/duktape/package';
  • directives : content: http,srv,if in srv

    • hi_duktape_package_cpath,default: ""

example:

  1. hi_duktape_package_cpath '/usr/local/nginx/duktape/package';
  • directives : content: loc,if in loc

    • hi_duktape_content,default: ""

example:

  1. location = /luaecho {
  2. hi_duktape_content "hi_res:status(200);hi_res:content('hello,world')" ;
  3. }
  • directives : content: loc,if in loc

    • hi_duktape_script,default: ""

example:

  1. location ~ \.lua$ {
  2. hi_duktape_script duktape;
  3. }

or

  1. location / {
  2. hi_duktape_script duktape/index.js;
  3. }
  • directives : content: http,srv,if in srv

    • hi_java_classpath,default:"-Djava.class.path=."

example:

  1. hi_java_classpath "-Djava.class.path=.:/usr/local/nginx/java:/usr/local/nginx/java/hi-nginx-java.jar";
  • directives : content: http,srv,if in srv

    • hi_java_options,default:"-server -d64 -Xmx1G -Xms1G -Xmn256m"

example:

  1. hi_java_options "-server -d64 -Xmx3G -Xms3G -Xmn768m -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseNUMA -XX:+CMSParallelRemarkEnabled -XX:MaxTenuringThreshold=15 -XX:MaxGCPauseMillis=30 -XX:GCPauseIntervalMillis=150 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -XX:+UseBiasedLocking -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15 -Dfml.ignorePatchDiscrepancies=true -Dfml.ignoreInvalidMinecraftCertificates=true -XX:+UseFastAccessorMethods -XX:+UseCompressedOops -XX:+OptimizeStringConcat -XX:+AggressiveOpts -XX:ReservedCodeCacheSize=2048m -XX:+UseCodeCacheFlushing -XX:SoftRefLRUPolicyMSPerMB=10000 -XX:ParallelGCThreads=10";
  • directives : content: loc,if in loc

    • hi_java_servlet,default:""

example:

  1. hi_java_servlet hi/jhello;
  • directives : content : http,srv,loc,if in loc ,if in srv

    • hi_java_servlet_cache_expires,default:300s

example:

  1. hi_java_servlet_cache_expires 300s;
  • directives : content : http,srv,loc,if in loc ,if in srv

    • hi_java_servlet_cache_size,default:10

example:

  1. hi_java_servlet_cache_size 10;
  • directives : content: http,srv,if in srv

    • hi_java_version,default:8

example:

  1. hi_java_version 8;
  • directives : content: loc,if in loc

    • hi_php_script,default: ""

example:

  1. location ~ \.php$ {
  2. hi_php_script php;
  3. }

or

  1. location / {
  2. hi_php_script php/index.php;
  3. }
  • directives : content: loc,if in loc

    • hi_javascript_lang,default:javascript

example:

  1. hi_javascript_lang javascript;
  • directives : content: loc,if in loc

    • hi_javascript_extension,default:js

example:

  1. hi_javascript_extension js;
  • directives : content: loc,if in loc

    • hi_javascript_content,default:""

example:

  1. hi_javascript_content "hi_res.content='hello,world';hi_res.status=200;";
  • directives : content: loc,if in loc

    • hi_javascript_script,default:""

example:

  1. hi_javascript_script javascript/index.js;

or

  1. hi_javascript_script javascript;
  • directives : content: http,srv,loc,if in loc ,if in srv

    • hi_javascript_compiledscript_expires,default:300s

example:

  1. hi_javascript_compiledscript_expires 5m;

特别说明

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

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

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

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

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