0

I try to check some parameters in request. Here is my url:

http://localhost:8080/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=004C0000064F&
     STYLES=&WIDTH=256&HEIGHT=256&FORMAT=image%2fjpeg&CRS=EPSG%3a100000&DPI=96&
 MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi%3a96&
BBOX=1530569.52624839870259166%2c524135.21126760687911883%2c1531064.27656850102357566%2c524629.96158770937472582

I trying to get REQUEST parameter. Here is my nginx 1.12.1 config:

server {
  listen      8080;
  server_name 127.0.0.1 localhost;

  set $site_backend localhost:56297;

  proxy_set_header  Host            $host;
  proxy_set_header  X-Real-IP       $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;

  location /favicon.ico {
      error_page 403 404  =  @tomcat_static_mapping;
  }

  location ~* /wms {

      internal;
      add_header URI $request_uri;
      add_header X-debug-message1 "$request_uri" always;

      if ($request_uri ~* REQUEST=([^&]*)) {
          add_header X-debug-message2 "hi" always;
          set $requesttype $1;
      } 
  }
}

And in browser i got header:

X-debug-message1: /wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=004C0000064F&STYLES=&WIDTH=256&HEIGHT=256&FORMAT=image%2fjpeg&CRS=EPSG%3a100000&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi%3a96&BBOX=1530569.52624839870259166%2c524135.21126760687911883%2c1531064.27656850102357566%2c524629.96158770937472582

But not get X-debug-message2 header. I check regular expression here https://rubular.com/ and it's found match and return GetMap as like i want.
What can be wrong here?

1 Answer 1

1

Something is not complete / matching in your post. I got X-debug-message2: hi only which does match to how nginx has to behave:

These directives are inherited from the previous level if and only if there are no add_header directives defined on the current level

For more intuitive outcome, use Headers-More module.

 more_set_headers "URI: $request_uri";
 more_set_headers 'X-debug-message1: "$request_uri"';
 location ~* /wms {
     if ($request_uri ~* REQUEST=([^&]*)) {
         more_set_headers 'X-debug-message2: hi';
         set $requesttype $1;
     }
 }
Sign up to request clarification or add additional context in comments.

5 Comments

When i removed X-debug-message1 header i still do not have X-debug-message2 header. So it's mean that code just to enter into my if check?
Yes. Are you actually requesting /wms? Things work as expected on my end.
Yeah i made typo in question text my url start with http://localhost:8080/wms?....
I did realize that and adjusted my test, but things still worked consistently on my end.
i found whats was wrong. It is a internal; option. Has no clue why it's block config normal work, but when i'd removed this row all work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.