Skip to content

support reverse proxy with path rewrite - #127

Merged
jmattheis merged 3 commits into
gotify:masterfrom
eternal-flame-AD:basepath
Feb 13, 2019
Merged

support reverse proxy with path rewrite#127
jmattheis merged 3 commits into
gotify:masterfrom
eternal-flame-AD:basepath

Conversation

@eternal-flame-AD

Copy link
Copy Markdown
Member

This fixes #122.

Changed the home path so that the page loads static assets relative to the page URL.

Also changed how API path is parsed so that the base path is considered.

@eternal-flame-AD

Copy link
Copy Markdown
Member Author

The nginx configuration I used to test this:

events {}
http {
    server {
        listen 127.0.0.1:10001;
        location /gotify/ {
            rewrite ^/gotify/(.*) /$1  break;
            proxy_pass http://127.0.0.1:10000$uri$is_args$args;
        }
        location /gotify/stream {
            rewrite ^/gotify/(.*) /$1  break;
            proxy_pass http://127.0.0.1:10000$uri$is_args$args;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
    }
}

@gotify gotify deleted a comment from codecov Bot Feb 11, 2019
@gotify gotify deleted a comment from codecov Bot Feb 11, 2019
@gotify gotify deleted a comment from codecov Bot Feb 11, 2019
@jmattheis
jmattheis self-requested a review February 11, 2019 16:27

@jmattheis jmattheis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, there are still some things todo.

The images for applications aren't properly mapped. (See api/application.go:323).

Loading the Swagger UI on the proxy can't load the swagger definition. (http://localhost:8080/gotify/docs)

If the swagger definition is loaded, then it will probably still not work, because no basepath is set inside the definition.

Having a trailing slash at the end redirects wrongly.
http://localhost:8080/gotify/docs/ -> http://localhost:8080/docs

I've used the following config with Caddy:

localhost:8080 

proxy /gotify localhost:80 {
   without /gotify
   transparent
}

proxy /gotify/stream localhost:80 {
	without /gotify
	websocket
	transparent
}

Comment thread ui/src/index.tsx
@eternal-flame-AD

eternal-flame-AD commented Feb 11, 2019

Copy link
Copy Markdown
Member Author

Loading the Swagger UI on the proxy can't load the swagger definition.

I think this is an existing issue because I found that even on my deployment without a reverse proxy I need to manually enter the spec URL to get the swagger definitions.

@codecov

codecov Bot commented Feb 12, 2019

Copy link
Copy Markdown

Codecov Report

Merging #127 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #127   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          39     39           
  Lines        1400   1400           
=====================================
  Hits         1400   1400

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09c1516...9a283ed. Read the comment docs.

@codecov

codecov Bot commented Feb 12, 2019

Copy link
Copy Markdown

Codecov Report

Merging #127 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #127   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          39     39           
  Lines        1400   1400           
=====================================
  Hits         1400   1400
Impacted Files Coverage Δ
docs/ui.go 100% <ø> (ø) ⬆️
docs/swagger.go 100% <100%> (ø) ⬆️
api/application.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09c1516...e1a3d61. Read the comment docs.

@eternal-flame-AD

Copy link
Copy Markdown
Member Author

I induced an API change that application image URLs are no longer resolved to absolute ones. Resolving URIs relative to the gotify path should be handled by the front-end, not back-end.

For the trailing slash problem I changed my nginx.conf, and now automatic redirects works:

events {}
http {
    server {
        listen 127.0.0.1:10001;
        location = /gotify {
            return 301 /gotify/;
        }
        location /gotify/ {
            rewrite ^/gotify/(.*) /$1  break;
            proxy_pass http://127.0.0.1:10000$uri$is_args$args;
            proxy_redirect ~^/(.*)$ /gotify/$1;
        }
        location /gotify/stream {
            rewrite ^/gotify/(.*) /$1  break;
            proxy_pass http://127.0.0.1:10000$uri$is_args$args;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
    }
}

For caddy config I guess it should be something like this(I am not very familiar with that, I just translated it from the nginx config and I havn't tested this extensively)
I did not find a way to let caddy rewrite 301/302 URLs from proxy upstream. I can only remove the response Location header to prevent the browser from recording incorrect 301 redirects.

localhost:10001

redir /gotify /gotify/

proxy /gotify/ localhost:10000 {
   without /gotify/
   transparent
   header_downstream -Location
}

proxy /gotify/stream localhost:10000 {
	without /gotify
	websocket
	transparent
}

Comment thread docs/ui.go

@jmattheis jmattheis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing how the images get returned breaks the api and would require an increment of the major version. (It also breaks the images in gotify/android). Tho' I can't think of an other way if we want to support path rewriting with a proxy.

This also breaks images in gotify/android.

Comment thread api/application.go Outdated
Comment thread ui/src/application/Applications.tsx
Comment thread docs/ui.go
Comment thread docs/swagger.go Outdated
@jmattheis jmattheis added this to the v1.3.0 milestone Feb 12, 2019

@jmattheis jmattheis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll use GitHub "squash" this time.

@jmattheis
jmattheis merged commit ec5b1f8 into gotify:master Feb 13, 2019
jmattheis pushed a commit to gotify/android that referenced this pull request Feb 17, 2019
714darwinrodriguez added a commit to 714darwinrodriguez/android-gradle-develop that referenced this pull request Sep 29, 2022
@jmattheis jmattheis mentioned this pull request Jul 2, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Possible to run from behind reverse proxy to directory

2 participants