Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1370 closed defect (invalid)

proxy_pass changes Content-Type to html when use variables

Reported by: tarunlalwani@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.13.x
Keywords: proxy_pass, content-type, Cc:
uname -a: Linux vagrant 4.4.0-66-generic #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.13.3
built by gcc 6.3.0 20170516 (Debian 6.3.0-18)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.13.3/debian/debuild-base/nginx-1.13.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

Description

$ nginx -v
nginx version: nginx/1.13.3

I am using latest nginx:latest docker image on a Vagrant box.

uname -a for vagrant box is

I have below proxy_pass

  location /abc/ {
    sub_filter_once off;
    sub_filter_types text/css;
    sub_filter '"base": "/"' '"base": "/abc/"';
    sub_filter '<head>' '<head>\n<base href="/abc/">';
    sub_filter 'src="/' 'src="./';
    sub_filter 'href="/' 'href="./';
    sub_filter 'url("/' 'url("./';
    sub_filter 'url(\'/' 'url(\'./';

    proxy_pass http://192.168.33.100:32770/;
  }

now if i get a css file

curl -IHTTP/1.1 200 OK
Server: nginx/1.13.3
Date: Tue, 29 Aug 2017 16:51:13 GMT
Content-Type: text/css
Connection: keep-alive
Content-Encoding: gzip "http://vm/abc/css/abc.css"

Now if i use variables in proxy_pass

  location /abc/ {
    sub_filter_once off;
    sub_filter_types text/css;
    sub_filter '"base": "/"' '"base": "/abc/"';
    sub_filter '<head>' '<head>\n<base href="/abc/">';
    sub_filter 'src="/' 'src="./';
    sub_filter 'href="/' 'href="./';
    sub_filter 'url("/' 'url("./';
    sub_filter 'url(\'/' 'url(\'./';
    set $proxyhost 192.168.33.100;
    set $proxyport 32770;
    proxy_pass http://$proxyhost:$proxyport/;
  }

Now if I repeat the same request

curl -I "http://vm/abc/css/abc.css"
HTTP/1.1 200 OK
Server: nginx/1.13.3
Date: Tue, 29 Aug 2017 16:52:49 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

The Content-Type gets changed to text/html. Why?

Change History (2)

comment:1 by Maxim Dounin, 7 years ago

Resolution: invalid
Status: newclosed

When using variables in proxy_pass, if URI is specified, it is passed to the server as is, replacing the original request URI. See docs for details.

comment:2 by tarunlalwani@…, 7 years ago

Thanks for the explanation, I was seeing valid response in browser and a content-type, didn't realize it was all the home page being served for every request. This helps.

Note: See TracTickets for help on using tickets.