0

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.

CoderLee
  • 3,079
  • 3
  • 25
  • 57
  • The tutorials cover the development mode. You would run your application with `morbo` during development on your machine, and remotely with `hypnotoad` or some other means when you deploy it for production. I believe there is a rather long guide on deployment in the github wiki for Mojolicious. Take a look there. – simbabque Oct 10 '17 at 17:56
  • I'll look it over, how would one view the pages in development from the remote host then before deploying? The tutorials don't seem to work past the computer in front of you. – CoderLee Oct 10 '17 at 18:01
  • Ah so you don't have any Perl on your computer? You always work with a remote box. I see. Is that the same one that you will also deploy? You are not working **on the production code**, are you? That would be... _daring_ ;) – simbabque Oct 10 '17 at 18:04
  • 1
    *"all the tutorials I could find only won't to show the localhost"* Please would you explain what you mean by this sentence? – Borodin Oct 10 '17 at 18:07
  • Production code is safe just trying to pick up mojolicious and use it like the other code which is remote, but it turns out to be more difficult than previously thought. The thrills of learning something new! – CoderLee Oct 10 '17 at 18:22
  • Maybe your production code runs as CGI? It's good that you are trying something! Keep that up. Mojo can run under CGI as well, and we've even had a question about that a few days ago. But if you have access to the web server and are not on a shared hosting environment I would not recommend it. – simbabque Oct 10 '17 at 18:34
  • Yeah I'm trying to get away from CGI hence Mojolicious, just having difficulty getting the proxy to work apparently. It's not that straight forward for new comers. – CoderLee Oct 10 '17 at 18:51
  • Did you get it to work? – simbabque Oct 14 '17 at 21:17
  • At long last this has been resolved. After modifying Apache for the proxy server I also had to change ownership of the directory I had the mojo app in. Now all is well it seems, and a big thanks to everyone who commented it helped! – CoderLee Oct 27 '17 at 05:11

1 Answers1

1

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.

simbabque
  • 53,749
  • 8
  • 73
  • 136