This is my setup for Mojolicious, but I think that the hoops I have to jump through there are not too different from the hoops for Dancer2:

My setup runs locally on http://localhost:3001 and gets remotely exposed as https://datenzoo.de/notes.

The Apache config is:

ProxyVia Block SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off <Location "/notes"> ProxyPass https://localhost:3001 RequestHeader set X-Forwarded-Host 'datenzoo.de' Header edit Location ^https(\:\/\/localhost/.*)$ https://datenzoo.de/n +otes/$1 Header edit Location ^https(\:\/\/localhost)$ https://datenzoo.de/note +s/ </Location>

In my Mojolicious code, I have to munge each request to have the proper value for the (proxied) URL:

# If we are behind a reverse proxy, prepend our path if ( my $path = $ENV{MOJO_REVERSE_PROXY} ) { my $path_uri = Mojo::URL->new($path); my @path_parts = grep /\S/, split m{/}, $path_uri->path; app->hook( before_dispatch => sub( $c ) { my $url = $c->req->url; warn "URL is <$url>"; my $base = $url->base; unshift @{ $base->path }, @path_parts; $base->path->trailing_slash(1); $url->path->leading_slash(0); #$url->scheme($path_uri->protocol); $base->scheme($path_uri->protocol); if( my $f = $c->req->headers->header('X-Forwarded-Host') and not $path_uri->host ) { # We could guess the host here if it wasn't set in MOJO_RE +VERSE_PROXY # This requires that the outside-facing server resets # X-Forwarded-Host , so that header is not allowed to be u +ser-controllable (my $host) = split /,/, $f; #$url->host( $host ); $base->host( $host ); } else { #$url->host($path_uri->host); $base->host($path_uri->host); } warn "Base is <$base>"; warn "URL is now <$url>"; $url->base( $base ); }); }

This still requires the code to know (via $ENV{MOJO_REVERSE_PROXY} the external URL, but I found no better way.


In reply to Re: Dancer2 App Deployment through Apache Proxy by Corion
in thread Dancer2 App Deployment through Apache Proxy by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.