配置例子
server {
listen 80;
server_name localhost;
userid on;
userid_name SESSIONID;
userid_domain localhost;
userid_path /;
client_max_body_size 100k;
hi_need_tokens off;
hi_cache_method GET;
hi_need_cache on;
hi_cache_size 10;
hi_cache_expires 300s;
hi_need_kvdb off;
hi_kvdb_size 10;
hi_kvdb_expires 5m;
hi_need_headers off;
hi_need_cookies off;
hi_need_session off;
hi_session_expires 300s;
hi_redis_host 127.0.0.1;
hi_redis_port 6379;
hi_java_classpath "-Djava.class.path=.:/usr/local/nginx/java:/usr/local/nginx/java/hi-nginx-java.jar";
hi_java_options "-server -d64 -Xms512m -Xmx512m -Xmn170m";
hi_java_servlet_cache_expires 300s;
hi_java_servlet_cache_size 10;
hi_java_version 8;
hi_lua_package_path '/usr/local/nginx/lua/?.lua;';
hi_lua_package_cpath '/usr/local/nginx/lua/?.so;';
hi_duktape_package_path '/usr/local/nginx/duktape/package';
hi_duktape_package_cpath '/usr/local/nginx/duktape/package';
location ~ \.py$ {
rewrite ^/(.*)\.py$ /$1 break;
hi_python_script python/index.py;
}
location ~ \.lua$ {
rewrite ^/(.*)\.lua$ /$1 break;
hi_lua_script lua/index.lua;
}
location ~ \.duktape$ {
rewrite ^/(.*)\.duktape$ /$1 break;
hi_duktape_script duktape/index.js;
}
location ~ \.php$ {
rewrite ^/(.*)\.php$ /$1 break;
hi_php_script php/index.php;
}
location ~ \.jsp$ {
rewrite ^/(.*)\.jsp$ /$1 break;
hi_java_servlet_cache_expires 60s;
hi_java_servlet hi/index;
}
location ~ \.do$ {
rewrite ^/(.*)\.do$ /$1 break;
hi cpp/index.so;
}
location ^~ /sub {
hi_subrequest '/query';
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__"))';
}
location ^~ /query {
internal;
proxy_pass http://http://hq.sinajs.cn/;
proxy_set_header Accept-Encoding '';
}
# curl -i http://localhost/sub?list=sh601006
location / {
hi_javascript_lang javascript;
hi_javascript_extension js;
hi_javascript_compiledscript_expires 5m;
hi_javascript_script javascript/index.js;
#hi_javascript_content "hi_res.content='hello,world';hi_res.status=200;";
}
}
特别说明
以上配置命令演示均使用相对路径。如果你按照配置启动后发现404错误,多半是你启动hi-nginx的方式使得相对路径无效。
这时,较差的建议是把配置改成绝对路径。较好的建议是只通过systemctl
启动,从而确保启动目录正确、从而相对路径有效。
修改配置后,一定要systemctl reload nginx
。
感谢网友热情地提出增加关于使用相对路径的特别说明
的建议。