comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 54:bcb5fce0b038 NGINX_0_1_27

nginx 0.1.27 *) Feature: the "blocked" parameter of the "valid_referers" directive. *) Change: the errors while handling the request header now logged at "info" level. The server name and the "Host" and "Referer" header lines also logged. *) Change: the "Host" header line is also logged in error log. *) Feature: the proxy_pass_unparsed_uri directive. The special handling of the "://" symbols in URI, appeared in 0.1.11 version, now is canceled. *) Bugfix: nginx could not be built on FreeBSD and Linux, if the --without-ngx_http_auth_basic_module configuration parameter was used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 28 Mar 2005 00:00:00 +0400
parents 0d75d65c642f
children 3050baa54a26
comparison
equal deleted inserted replaced
53:b6565ddf033b 54:bcb5fce0b038
103 { ngx_string("proxy_preserve_host"), 103 { ngx_string("proxy_preserve_host"),
104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
105 ngx_conf_set_flag_slot, 105 ngx_conf_set_flag_slot,
106 NGX_HTTP_LOC_CONF_OFFSET, 106 NGX_HTTP_LOC_CONF_OFFSET,
107 offsetof(ngx_http_proxy_loc_conf_t, preserve_host), 107 offsetof(ngx_http_proxy_loc_conf_t, preserve_host),
108 NULL },
109
110 { ngx_string("proxy_pass_unparsed_uri"),
111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
112 ngx_conf_set_flag_slot,
113 NGX_HTTP_LOC_CONF_OFFSET,
114 offsetof(ngx_http_proxy_loc_conf_t, pass_unparsed_uri),
108 NULL }, 115 NULL },
109 116
110 { ngx_string("proxy_set_x_url"), 117 { ngx_string("proxy_set_x_url"),
111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 118 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
112 ngx_conf_set_flag_slot, 119 ngx_conf_set_flag_slot,
800 807
801 u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) 808 u_char *ngx_http_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len)
802 { 809 {
803 u_char *p; 810 u_char *p;
804 ngx_int_t escape; 811 ngx_int_t escape;
805 ngx_str_t uri;
806 ngx_http_request_t *r; 812 ngx_http_request_t *r;
807 ngx_peer_connection_t *peer; 813 ngx_peer_connection_t *peer;
808 ngx_http_proxy_log_ctx_t *ctx; 814 ngx_http_proxy_log_ctx_t *ctx;
809 ngx_http_proxy_upstream_conf_t *uc; 815 ngx_http_proxy_upstream_conf_t *uc;
810 816
812 r = ctx->proxy->request; 818 r = ctx->proxy->request;
813 uc = ctx->proxy->lcf->upstream; 819 uc = ctx->proxy->lcf->upstream;
814 peer = &ctx->proxy->upstream->peer; 820 peer = &ctx->proxy->upstream->peer;
815 821
816 p = ngx_snprintf(buf, len, 822 p = ngx_snprintf(buf, len,
817 " while %s, client: %V, host: %V, URL: \"%V\"," 823 " while %s, client: %V, server: %V, URL: \"%V\","
818 " upstream: http://%V%s%V", 824 " upstream: http://%V%s%V",
819 ctx->proxy->action, 825 ctx->proxy->action,
820 &r->connection->addr_text, 826 &r->connection->addr_text,
821 &r->server_name, 827 &r->server_name,
822 &r->unparsed_uri, 828 &r->unparsed_uri,
824 ctx->proxy->lcf->upstream->uri_separator, 830 ctx->proxy->lcf->upstream->uri_separator,
825 &ctx->proxy->lcf->upstream->uri); 831 &ctx->proxy->lcf->upstream->uri);
826 len -= p - buf; 832 len -= p - buf;
827 buf = p; 833 buf = p;
828 834
835 if (ctx->proxy->lcf->pass_unparsed_uri && r->valid_unparsed_uri) {
836 p = ngx_cpymem(buf, r->unparsed_uri.data + 1, r->unparsed_uri.len - 1);
837 len -= p - buf;
838
839 return ngx_http_log_error_info(r, p, len);
840 }
841
829 if (r->quoted_uri) { 842 if (r->quoted_uri) {
830 escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len, 843 escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
831 r->uri.len - uc->location->len, 844 r->uri.len - uc->location->len,
832 NGX_ESCAPE_URI); 845 NGX_ESCAPE_URI);
833 } else { 846 } else {
839 852
840 ngx_escape_uri(buf, r->uri.data + uc->location->len, 853 ngx_escape_uri(buf, r->uri.data + uc->location->len,
841 r->uri.len - uc->location->len, NGX_ESCAPE_URI); 854 r->uri.len - uc->location->len, NGX_ESCAPE_URI);
842 855
843 buf += r->uri.len - uc->location->len + escape; 856 buf += r->uri.len - uc->location->len + escape;
844 857 len -= r->uri.len - uc->location->len + escape;
845 if (r->args.len == 0) { 858
846 return buf; 859 if (r->args.len) {
860 p = ngx_snprintf(buf, len, "?%V", &r->args);
861 len -= p - buf;
862 buf = p;
847 } 863 }
848 864
849 len -= r->uri.len - uc->location->len + escape; 865 return ngx_http_log_error_info(r, buf, len);
850
851 return ngx_snprintf(buf, len, "?%V", &r->args);
852 } 866 }
853 867
854 p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape); 868 p = ngx_palloc(r->pool, r->uri.len - uc->location->len + escape);
855 if (p == NULL) { 869 if (p == NULL) {
856 return buf; 870 return buf;
857 } 871 }
858 872
859 ngx_escape_uri(p, r->uri.data + uc->location->len, 873 ngx_escape_uri(p, r->uri.data + uc->location->len,
860 r->uri.len - uc->location->len, NGX_ESCAPE_URI); 874 r->uri.len - uc->location->len, NGX_ESCAPE_URI);
861 875
862 uri.len = r->uri.len - uc->location->len + escape; 876 p = ngx_cpymem(buf, p, r->uri.len - uc->location->len + escape);
863 uri.data = p;
864 877
865 } else { 878 } else {
866 uri.len = r->uri.len - uc->location->len; 879 p = ngx_cpymem(buf, r->uri.data + uc->location->len,
867 uri.data = r->uri.data + uc->location->len; 880 r->uri.len - uc->location->len);
868 881 }
869 } 882
870 883 len -= p - buf;
871 return ngx_snprintf(buf, len, "%V%s%V", 884 buf = p;
872 &uri, r->args.len ? "?" : "", &r->args); 885
886 if (r->args.len) {
887 p = ngx_snprintf(buf, len, "?%V", &r->args);
888 len -= p - buf;
889 buf = p;
890 }
891
892 return ngx_http_log_error_info(r, buf, len);
873 } 893 }
874 894
875 895
876 static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r, 896 static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r,
877 uintptr_t data) 897 uintptr_t data)
1107 1127
1108 conf->connect_timeout = NGX_CONF_UNSET_MSEC; 1128 conf->connect_timeout = NGX_CONF_UNSET_MSEC;
1109 conf->send_timeout = NGX_CONF_UNSET_MSEC; 1129 conf->send_timeout = NGX_CONF_UNSET_MSEC;
1110 conf->send_lowat = NGX_CONF_UNSET_SIZE; 1130 conf->send_lowat = NGX_CONF_UNSET_SIZE;
1111 1131
1132 conf->pass_unparsed_uri = NGX_CONF_UNSET;
1112 conf->preserve_host = NGX_CONF_UNSET; 1133 conf->preserve_host = NGX_CONF_UNSET;
1113 conf->set_x_url = NGX_CONF_UNSET; 1134 conf->set_x_url = NGX_CONF_UNSET;
1114 conf->set_x_real_ip = NGX_CONF_UNSET; 1135 conf->set_x_real_ip = NGX_CONF_UNSET;
1115 conf->add_x_forwarded_for = NGX_CONF_UNSET; 1136 conf->add_x_forwarded_for = NGX_CONF_UNSET;
1116 1137
1146 1167
1147 ngx_conf_merge_msec_value(conf->connect_timeout, 1168 ngx_conf_merge_msec_value(conf->connect_timeout,
1148 prev->connect_timeout, 60000); 1169 prev->connect_timeout, 60000);
1149 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); 1170 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
1150 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); 1171 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
1172
1173 ngx_conf_merge_value(conf->pass_unparsed_uri, prev->pass_unparsed_uri, 0);
1174
1175 if (conf->pass_unparsed_uri && conf->upstream->location->len > 1) {
1176 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1177 "\"proxy_pass_unparsed_uri\" can be set for "
1178 "location \"/\" or given by regular expression.");
1179 return NGX_CONF_ERROR;
1180 }
1151 1181
1152 ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0); 1182 ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0);
1153 ngx_conf_merge_value(conf->set_x_url, prev->set_x_url, 0); 1183 ngx_conf_merge_value(conf->set_x_url, prev->set_x_url, 0);
1154 ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0); 1184 ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0);
1155 ngx_conf_merge_value(conf->add_x_forwarded_for, 1185 ngx_conf_merge_value(conf->add_x_forwarded_for,