New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse proxy configuration (nginx) #82

Closed
flocke opened this Issue Nov 19, 2018 · 10 comments

Comments

5 participants
@flocke
Copy link

flocke commented Nov 19, 2018

Could someone please share his working reverse proxy configuration for nginx?

I am currently running gotify under it's own subdomain using a reverse proxy with nginx,
but my client keeps reconnecting a lot. I assume there is something wrong with my timeouts,
but I don't really know which values to chose.

@fgerling

This comment has been minimized.

Copy link

fgerling commented Nov 19, 2018

I would be helpful if you show us your nginx config.

Did you configured the /stream websocket endpoint in your nginx config file?

location /stream {
        proxy_pass http://127.0.0.1:8942;
        proxy_set_header   Host        $host;
        proxy_set_header   X-Real-IP   $remote_addr;
        proxy_set_header   Upgrade     $http_upgrade;
        proxy_set_header   Connection  "Upgrade";
}
@flocke

This comment has been minimized.

Copy link

flocke commented Nov 19, 2018

I'm not home right now, but I will post my config once I am.

Right now I have the config only for /, which looks a lot like yours. Do I have to define /stream really seperately?

@jmattheis

This comment has been minimized.

Copy link
Member

jmattheis commented Nov 19, 2018

This is my configuration:

location / {
  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header        X-Forwarded-Proto $scheme;
  proxy_pass http://127.0.0.1:6666/;
  proxy_buffering off;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_connect_timeout 7d;
  proxy_send_timeout 7d;
  proxy_read_timeout 7d;
}

@jmattheis jmattheis added the question label Nov 19, 2018

@flocke

This comment has been minimized.

Copy link

flocke commented Nov 19, 2018

Mine was just

location / {
    proxy_pass http://gotify;

    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    proxy_buffering off;
}

with

upstream gotify {
    server 127.0.0.1:8080;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

defined earlier.

I'm gonna try the additional headers and longer timeouts from @jmattheis and report back.

@flocke

This comment has been minimized.

Copy link

flocke commented Nov 19, 2018

It seems to work out great so far. I have been running it for the last 3h and I have yet to see a disconnect. I'm gonna keep an eye on the battery consumption as well tomorrow.

@flocke

This comment has been minimized.

Copy link

flocke commented Nov 20, 2018

The 7d timeout seems to have increased the battery consumption a lot:

I now switched to a timeout if 1h, which seems reasonable to me and it has been a lot better (only about 2% in the same timeframe). I'm gonna run with it a while and see what happens. I'm gonna close this issue for now.

@flocke flocke closed this Nov 20, 2018

@L11R

This comment has been minimized.

Copy link

L11R commented Nov 28, 2018

@flocke 7d is crazy timeframe. And even 1h is pretty much. Server should send pings and refresh timeout. So it should be a little bit more than Gotify server timeout. According to this line:

streamHandler := stream.New(200*time.Second, 15*time.Second)

We need twice timeout I guess, 400 seconds, or just 5-7 minutes.

@flocke

This comment has been minimized.

Copy link

flocke commented Nov 28, 2018

@L11R Yeah, that seems much more reasonable. I'm gonna test it on my server and report back.

@flocke

This comment has been minimized.

Copy link

flocke commented Nov 29, 2018

I went with a 7 min timeout and it seems to be working nicely. I also figured out that the high battery drain mostly occurrs when I am in an area with bad reception and Gotify has to reconnect a lot.

@doronbehar

This comment has been minimized.

Copy link

doronbehar commented Jan 1, 2019

Hey @fgerling, I've had the same problem as @flocke with nginx and I used your configuration example from this comment: #82 (comment)

But, I've had to make a small change to that - instead of proxy_pass http://127.0.0.1:8001 I used proxy_pass http://127.0.0.1:8001/stream and it worked.

Additionally, speaking of perhaps there should be included in the repository an example configuration for nginx as a proxy server of gotify?

lapin-b added a commit to lapin-b/server that referenced this issue Jan 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment