关于Nginx的SSI(包含路径)
若是shtml里面的网页代码包含语句写成以下:
<!--#include virtual="/test.html"-->
这样是没有问题,能够包含的,可是若是写成这样:html <!--#include virtual="../test.html"-->因为须要包含当前代码文件所在目录路径的上级目录文件,nginx会为此请求产生的子请求uri为/../test.html,默认nginx会认为这个uri并非安全的,日志(error_log)会输入以下错误:nginx unsafe URI "/../test.html" was detected while sending response to client, client: 192.168.10.204, server: test.aijuzhe.cn, 不能正确包含文件,页面会输出[an error occurred while processing the directive],解决方法是找到nginx源代码目录的unsafe uri检查函数并强制使其返回一个NGX_OK,即以下文件:ide vi nginx-VERSION/src/http/ngx_http_parse.c找到ngx_http_parse_unsafe_uri函数,并在前面加入一句return NGX_OK;函数 ngx_int_tngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,ngx_str_t *args, ngx_uint_t *flags){return NGX_OK; /*这一句是后面加的*/u_char ch, *p;size_t len;len = uri->len;p = uri->data;if (len == 0 || p[0] == '?') {goto unsafe;}if (p[0] == '.' && len == 3 && p[1] == '.' && (p[2] == '/'#if (NGX_WIN32)|| p[2] == '\\'#endif)){goto unsafe;}for ( /* void */ ; len; len--) {ch = *p++;if (usual[ch >> 5] & (1 << (ch & 0x1f))) {continue;}if (ch == '?') {args->len = len - 1;args->data = p;uri->len -= len;return NGX_OK;}if (ch == '\0') {*flags |= NGX_HTTP_ZERO_IN_URI;continue;}if ((ch == '/'#if (NGX_WIN32)|| ch == '\\'#endif) && len > 2){/* detect "/../" */if (p[0] == '.' && p[1] == '.' && p[2] == '/') {goto unsafe;}#if (NGX_WIN32)if (p[2] == '\\') {goto unsafe;}if (len > 3) {/* detect "/.../" */if (p[0] == '.' && p[1] == '.' && p[2] == '.'&& (p[3] == '/' || p[3] == '\\')){goto unsafe;}}#endif}}return NGX_OK;unsafe:ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,"unsafe URI \"%V\" was detected", uri);return NGX_ERROR;}从新编译之后nginx能够包含上级目录的文件,固然,带来的后果是安全性的降低。ui |