关于Nginx的SSI(包含路径)
如果shtml里面的网页代码包含语句写成如下: 这样是没有问题,可以包含的,但是如果写成这样:由于需要包含当前代码文件所在目录路径的上级目录文件,nginx会为此请求产生的子请求uri为/../test.html,默认nginx会认为这个uri并不是安全的,日志(error_log)会输入如下错误:
unsafe URI "/../test.html" was detected while sending response to client, client: 192.168.10.204, server: test.aijuzhe.cn,
request: "GET /test.shtml HTTP/1.1", host: "test.aijuzhe.cn", referrer: "http://test.aijuzhe.cn/test.shtml"
不能正确包含文件,页面会输出,解决方法是找到nginx源代码目录的unsafe uri检查函数并强制使其返回一个NGX_OK,即如下文件:
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 == '?') {goto unsafe;}if (p == '.' && len == 3 && p == '.' && (p == '/'#if (NGX_WIN32)|| p == '\\'#endif)){goto unsafe;}for ( /* void */ ; len; len--) {ch = *p++;if (usual & (1 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 == '.' && p == '.' && p == '/') {goto unsafe;}#if (NGX_WIN32)if (p == '\\') {goto unsafe;}if (len > 3) {/* detect "/.../" */if (p == '.' && p == '.' && p == '.'&& (p == '/' || p == '\\')){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可以包含上级目录的文件,当然,带来的后果是安全性的下降。
页:
[1]