Hello,

I'm trying to use the Mojolicious plugin OpenAPI to serve two APIs (https://api1.example.com and https://api2.example.com) and a website (https://www.example.com)

I started from the very useful page https://perlmaven.com/deploying-a-mojolicious-application and enabled my sites on Apache with a conf file like this below.

<VirtualHost *:443> ServerAdmin info@example.com ServerName www.example.com SSLProxyEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3000/" keepalive=On # :3000 for morbo, :8082 for hypnotoad ProxyPassReverse "/" "http://127.0.0.1:3000/" RequestHeader set X-Forwarded-HTTPS "0" ErrorLog /home/common/logs/www.example.com/error.log LogLevel warn CustomLog /home/common/logs/www.example.com/access.log combined # Use the multisites cert SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain +.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privke +y.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> <VirtualHost *:443> ServerAdmin info@example.com ServerName api1.example.com SSLProxyEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3000/" keepalive=On ProxyPassReverse "/" "http://127.0.0.1:3000/" RequestHeader set X-Forwarded-HTTPS "0" LogLevel debug ErrorLog /home/common/logs/api1.example.com/error.log CustomLog /home/common/logs/api1.example.com/access.log combined SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain +.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privke +y.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> <VirtualHost *:443> ServerAdmin info@example.com ServerName api2.example.com SSLProxyEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPreserveHost On ProxyPass "/" "http://127.0.0.1:3000/" keepalive=On ProxyPassReverse "/" "http://127.0.0.1:3000/" RequestHeader set X-Forwarded-HTTPS "0" ErrorLog /home/common/logs/api2.example.com/error.log LogLevel warn CustomLog /home/common/logs/api2.example.com/access.log combined Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain +.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privke +y.pem </VirtualHost> <VirtualHost *:80> ServerAdmin info@example.com ServerName www.example.com RewriteEngine on RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=perma +nent] </VirtualHost> <VirtualHost *:80> ServerAdmin info@example.com ServerName api1.example.com RewriteEngine on RewriteCond %{SERVER_NAME} =api1.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=perma +nent] </VirtualHost> <VirtualHost *:80> ServerAdmin info@example.com ServerName api2.example.com RewriteEngine on RewriteCond %{SERVER_NAME} =api2.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=perma +nent] </VirtualHost>

I then start my application (with morbo or hypnotoad) like so:

use Mojolicious::Lite; app->config( hypnotoad => { listen => [ 'http://127.0.0.1:8082/' ], proxy => 1, }, morbo => { listen => [ 'http://127.0.0.1:3000/' ], proxy => 1, }, ); plugin Mount => { 'api1.example.com' => '/home/common/api1.example.com +/script/api' }; # API1 plugin Mount => { 'api2.example.com' => '/home/common/api2.example.com +/script/api' }; # API2 plugin Mount => { 'www.example.com' => '/home/common/www.example.com/s +cript/website' }; #WEBSITE

API1 and API2 use the OpenAPI plugin. When I test from prompt the two APIs with prove I see they work. Similarly, if I run api routes I see all the endpoints defined in the yaml API definition file.
Instead, when I call these APIs from remote, the endpoint I request is always routed via the first specified Mount, i.e., assuming the order above, when I call an endpoint of API2 it is not found because I see the GET operation is for a route in API1.
If I invert the mount order, the endpoints of API1 are searched as routes of API2.
The same happens when browsing the index.html page in the public folder of API2: I get the index.html page of API1. I don't know if that means the problem has nothing to do with OpeAPI
The website (third Mount, no OpenAPI) is instead working as expected.
I hope you can give me some hint, I'm lost. Thanks


In reply to Mojolicious+OpenAPI behind Apache Proxy by Anonymous Monk

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.