... | ... |
@@ -11,5 +11,15 @@ |
11 | 11 |
;;; Forget to comment out after resetting password. |
12 | 12 |
;reset_password=1 |
13 | 13 |
|
14 |
+[reverse_proxy] |
|
15 |
+;;; Reverse proxy support |
|
16 |
+;on=1 |
|
17 |
+ |
|
18 |
+;;; Reverse proxy path depth |
|
19 |
+;;; If proxy path is http://somehost.com/foo, you set path_depth to 1. |
|
20 |
+;;; If proxy path is http://somehost.com/foo/bar, you set path_depth to 2. |
|
21 |
+;path_depth=1 |
|
22 |
+;path_depth=2 |
|
23 |
+ |
|
14 | 24 |
[hypnotoad] |
15 | 25 |
listen=http://*:10020 |
... | ... |
@@ -214,18 +214,22 @@ sub startup { |
214 | 214 |
$r->get('/network/graph')->name('network_graph'); |
215 | 215 |
} |
216 | 216 |
} |
217 |
- |
|
217 |
+ |
|
218 | 218 |
# Reverse proxy support |
219 |
- $ENV{MOJO_REVERSE_PROXY} = 1; |
|
220 |
- $self->hook('before_dispatch' => sub { |
|
221 |
- my $self = shift; |
|
222 |
- |
|
223 |
- if ($self->req->headers->header('X-Forwarded-Host')) { |
|
224 |
- my $prefix = shift @{$self->req->url->path->parts}; |
|
225 |
- push @{$self->req->url->base->path->parts}, $prefix |
|
226 |
- if defined $prefix; |
|
219 |
+ my $reverse_proxy_on = $self->config->{reverse_proxy}{on}; |
|
220 |
+ my $path_depth = $self->config->{reverse_proxy}{path_depth}; |
|
221 |
+ if ($reverse_proxy_on) { |
|
222 |
+ $ENV{MOJO_REVERSE_PROXY} = 1; |
|
223 |
+ if ($path_depth) { |
|
224 |
+ $self->hook('before_dispatch' => sub { |
|
225 |
+ my $self = shift; |
|
226 |
+ for (1 .. $path_depth) { |
|
227 |
+ my $prefix = shift @{$self->req->url->path->parts}; |
|
228 |
+ push @{$self->req->url->base->path->parts}, $prefix; |
|
229 |
+ } |
|
230 |
+ }); |
|
227 | 231 |
} |
228 |
- }); |
|
232 |
+ } |
|
229 | 233 |
} |
230 | 234 |
|
231 | 235 |
1; |