Problems with map + subfilter + proxy

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with map + subfilter + proxy

Jorge Pereira
Folks,

1. I have tried to use the map+subfilter as the below snip.

user nginx;
worker_processes auto;

daemon off;

events {
  worker_connections  1024;
}

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  log_format  main '$remote_addr - $remote_user [$time_local] "$request" '
                   '$status $body_bytes_sent "$http_referer" '
                   '"$http_user_agent" "$http_x_forwarded_for" '
                   '(Cache $upstream_cache_status)';

  access_log /dev/stdout main;

  sendfile on;
  keepalive_timeout 65;
  gzip on;

  # Due to we are listening only http, therefore be sure to always return http://
  map $request_uri $subfilter_allowed_content_type {
    volatile;
    default                         whatever/donothing;
    ~/artifactory/api/nuget/.*      application/atom+xml;
  }

  proxy_cache_path /var/cache/nginx/artifactory
                   levels=1:2
                   keys_zone=artifactory_cache:50m
                   max_size=50g
                   inactive=24h
                   use_temp_path=off;

  server {
    listen 80;
    server_name ~(?<repo>.+)\.artifactory.tapioca.lan;

    resolver 8.8.8.8;

    set $upstream https://artifactory.myaws.com/artifactory;

    location /artifactory/ {
      sub_filter_types $subfilter_allowed_content_type;   # the variable is filled up correctly
      #sub_filter_types "application/atom+xml";           # but, when use it hardcode. then it works fine.

      sub_filter_last_modified on;
      sub_filter "https://$host" http://$host";           # it works only when use sub_filter_types with hardcore value.
      sub_filter_once off;

      # its been filled correctly
      add_header X-Debug-subfilter-allowed-content-type "$subfilter_allowed_content_type";

      proxy_read_timeout  60s;
      proxy_pass_header   Server;
      proxy_cookie_path   ~*^/.* /;

      if ( $request_uri ~ ^/artifactory/(.*)$ ) {
        proxy_pass        $upstream/$1;
      }

      proxy_pass          $upstream;

      proxy_set_header    Host              $http_host;
      proxy_set_header    X-Forwarded-Port  $server_port;
      proxy_set_header    X-Forwarded-Proto $http_x_forwarded_proto;
      proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
      proxy_set_header    X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory;
      proxy_set_header    X-JFrog-Art-Api   $artifactory_token;
    }
  }
}

2. I do the request like.

curl -s -H "Host: artifactory-proxy.mylan.fni" " http://172.17.0.2/artifactory/api/nuget/v3/dtfni-nuget/Packages(Id='AttributeRouting.Core.Web',Version='3.5.6')"

Conclusion: the variable it been filled up correctly, but the sub_filter_types looks to not process. Someone has any suggestion?

ps: I am using the nginx 1.12.x


--
Jorge Pereira

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Problems with map + subfilter + proxy

Francis Daly
On Wed, Nov 07, 2018 at 08:47:15PM -0200, Jorge Pereira wrote:

Hi there,

>     location /artifactory/ {
>       sub_filter_types $subfilter_allowed_content_type;   # the
> variable is filled up correctly
>       #sub_filter_types "application/atom+xml";           # but, when
> use it hardcode. then it works fine.

If the documentation for a directive (available here at
http://nginx.org/r/sub_filter_types) does not say that the value can
contain variables, then the value probably does not process $variable
content.

>       sub_filter "https://$host" http://$host";           # it works
> only when use sub_filter_types with hardcore value.

Compare with the documentation for this directive - http://nginx.org/r/sub_filter

> Conclusion: the variable it been filled up correctly, but the
> sub_filter_types looks to not process. Someone has any suggestion?

sub_filter_types does not read variables. If you set the type to the
string "$subfilter_allowed_content_type", sub_filter might take effect. (I
haven't tested, since it is not a useful case, I think.)

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx