Being very new to Mojolicious I am having trouble with getting my apps to work. I am running everything off of a remote server, but all the tutorials I could find only want to show the localhost way of deploying. As the title indicates I am getting 500 internal server errors instead of the apps being loaded/ran and don't really know why. Could someone explain how this is done for those not using a local machine to run their apps at?
Here is the demo app all nice and pretty as generated:
#!/usr/bin/env perl
use Mojolicious::Lite;
# Documentation browser under "/perldoc"
plugin 'PODRenderer';
get '/test' => sub {
my $c = shift;
$c->render(template => 'index');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
To learn more, you can browse through the documentation
<%= link_to 'here' => '/perldoc' %>.
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
Everything loads fine and the hypnotoad command returns:
Listening at "http://*:8080"
Server available at http://127.0.0.1:8080
What needs to be done to get this app to load via website url instead of localhost?
Apologies if this seems like a silly question but there doesn't appear to be any obvious tutorials or much discussion on running mojo apps from a remote server so any help is appriciated as I am sure other newbies have encountered a similar problem before and more to come.
What you need to do depends on the setup of the machine you are running this on, and the network between that server and the computer(s) you want to access it from.
In general the available at http://127.0.0.1:8080 is just the default text. If your server allows port 8080 to be accessed from the outside, then you can already reach it via the server's IP address or hostname, and port 8080.
$ curl 192.168.0.4:8080/
$ curl myserver.local:8080/
Those are contrived examples obviously.
If you want to make it available on a domain you bought, you will either need to make hypnotoad
listen on port 80 and ensure there is no other webserver (like an Apache) running on the box, or you will need to set up a proxy in the webserver that is running which will forward requests to e.g. /
to port 8080.
There is quite a lot of information on deployment in the Mojo wiki on github, and one of the pages listed there talks about hypnotoad
in detail, listing for example the proxy solution together with Apache:
Access through proxy server
In production deployment, generally proxy server is used to access hypnotoad server. The following is apache/mod_proxy config file example using virtual host.
<VirtualHost *:80> ServerName app1.somehost.com ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost>
See the various webserver sections under "DEPLOYMENT" in Mojolicious::Guides::Cookbook for details on reverse-proxying to your app, and for pointers on getting
X-Forwarded-For
headers set and honoured by Mojo.