Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Changes to location regexp broke previously working configs #39

Open
kscherer opened this issue Mar 7, 2018 · 8 comments
Open

Changes to location regexp broke previously working configs #39

kscherer opened this issue Mar 7, 2018 · 8 comments
Labels

Comments

@kscherer
Copy link
Contributor

kscherer commented Mar 7, 2018

Prior to commit 2379d2d I had the following:

  SERVER1REVERSE_PROXY_LOCATION1: "/"
  SERVER1REVERSE_PROXY_PASS1: "http://layerindex:5000/"
  SERVER1REVERSE_PROXY_APPLICATION1: "custom"
  SERVER1REVERSE_PROXY_HEADER1FIELD1: 'Host $$http_host'
  SERVER1REVERSE_PROXY_HEADER1FIELD2: 'X-Forwarded-For $$proxy_add_x_forwarded_for'
  SERVER1REVERSE_PROXY_HEADER1FIELD3: 'X-Forwarded-Host $$host'
  SERVER1REVERSE_PROXY_HEADER1FIELD4: 'X-Forwarded-Proto $$scheme'
  SERVER1REVERSE_PROXY_DIRECTIVE1FIELD1: 'proxy_redirect off'

which created the following config:

    location / {
      proxy_pass http://layerindex:5000/;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_redirect off;
    }

After the commit the config looks like this:

    location ~* ^/(.*) {
      set $backend "http://layerindex:5000/";
      proxy_pass $backend$1$is_args$args;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_redirect off;
    }

The only way to make it work was to add:

SERVER1REVERSE_PROXY_DISABLE_RESOLVER1: "true"

to revert this behavior. What am I missing? Why was the default behavior changed? A notification about breaking changes would have been much appreciated.

@blacklabelops
Copy link
Collaborator

blacklabelops commented Mar 8, 2018

@kscherer
Copy link
Contributor Author

kscherer commented Mar 8, 2018

I did see that message and tried removing the trailing slash. But the following configuration still results in a broken config:

SERVER1REVERSE_PROXY_LOCATION1: "/"
SERVER1REVERSE_PROXY_PASS1: "http://layerindex:5000"
SERVER1REVERSE_PROXY_APPLICATION1: "custom"
SERVER1REVERSE_PROXY_HEADER1FIELD1: 'Host $$http_host'
SERVER1REVERSE_PROXY_HEADER1FIELD2: 'X-Forwarded-For $$proxy_add_x_forwarded_for'
SERVER1REVERSE_PROXY_HEADER1FIELD3: 'X-Forwarded-Host $$host'
SERVER1REVERSE_PROXY_HEADER1FIELD4: 'X-Forwarded-Proto $$scheme'
SERVER1REVERSE_PROXY_DIRECTIVE1FIELD1: 'proxy_redirect off'

Nginx reports the following error:

[error] 57#57: *6 invalid port in upstream "layerindex:5000layerindex/", client: , server: _, request: "GET /layerindex/ HTTP/1.1", host: ""

The change also does not work with the staticfiles patch that I submitted earlier unless I explicitly disable the resolver.

@blacklabelops
Copy link
Collaborator

Same here, does not work at all. Dunno how I tested this.

@blacklabelops
Copy link
Collaborator

Reverse proxy now adding the missing slash.

@kscherer
Copy link
Contributor Author

kscherer commented Mar 9, 2018

I can confirm that the latest commit fixed the problem with the reverse proxy port parsing, but the staticfiles feature still needs to disable the resolver to work.

  SERVER1REVERSE_PROXY_LOCATION2: "/static/"
  SERVER1REVERSE_PROXY_APPLICATION2: "custom"
  SERVER1REVERSE_PROXY_DISABLE_RESOLVER2: "true"
  SERVER1REVERSE_PROXY_DIRECTIVE2FIELD1: 'alias /var/lib/nginx/html/static/'
  SERVER1REVERSE_PROXY_DIRECTIVE2FIELD2: 'autoindex on'

I tried removing the trailing slash from Location and from the alias and neither changed the behavior. If this can't be fixed, then an update to the docs should be sufficient

@blacklabelops
Copy link
Collaborator

Okay checking static files feature.

@kscherer
Copy link
Contributor Author

kscherer commented Mar 9, 2018

Actually it is a little more complicated than that. If the resolver is enabled for LOCATION1, LOCATION2 fails regardless if the resolver is enabled or disabled.

@blacklabelops
Copy link
Collaborator

I was able to serve static files:

docker run -d \
    -p 80:80 \
    -v $(pwd)/htmltest:/htmltest \
    --name nginx \
    -e "SERVER1REVERSE_PROXY_LOCATION1=/" \
    -e "SERVER1REVERSE_PROXY_APPLICATION1=custom" \
    -e "SERVER1REVERSE_PROXY_DIRECTIVE1FIELD1=root /htmltest" \
    -e "SERVER1REVERSE_PROXY_DIRECTIVE1FIELD2=autoindex on" \
    blacklabelops/nginx

and this

docker run -d \
    -p 80:80 \
    -v $(pwd)/htmltest:/htmltest/static \
    --name nginx \
    -e "SERVER1REVERSE_PROXY_LOCATION1=/static" \
    -e "SERVER1REVERSE_PROXY_APPLICATION1=custom" \
    -e "SERVER1REVERSE_PROXY_DIRECTIVE1FIELD1=root /htmltest/" \
    -e "SERVER1REVERSE_PROXY_DIRECTIVE1FIELD2=autoindex on" \
    blacklabelops/nginx

If you want to use dynamic and static on the reverse proxy you should do this:

  1. Disable the resolver for the static serve
  2. Swap reverse proxies. Define static serve as first, then dynamic part as second.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants