Deploying web applications with Mojolicious

This is an explanation of how to deploy a web application with Mojolicious. Mojolicious is a scalable for the real-time web. Perl web framework.

Install Mojolicious

Install Mojolicious. User Perl and cpanm must be installed.

cpanm Mojolicious

Creating a Mojolicious application

Mojolicious Let's create an application.

The application name is "Webapp".

Run the "mojo generate app" command to create a Mojolicious application.

mojo generate app web app

A directory called webapp will be created and the Mojolicious application will be placed in it.

Start Mojolicious's development server

Start the Mojolicious development server with the morbo command.

cd ~ / webapp
morbo script / webapp

The port number is 3000 and the web application starts.

Web application available at http://127.0.0.1:3000

The "127.0.0.1" part is the loopback address, so let's change it to the IP address of the server and access it.

If the IP address of the server is "132.165.23.8", you can access it with the following.

http://132.165.23.8:3000

If you can't access it, make sure your network firewall settings allow port 3000.

If successful, the screen will display "Welcome to the Mojolicious real-time web framework!".

You can exit with "Ctrl + C".

Start Mojolicious production server

Start Mojolicious's production server with the hypnotoad command. hypnotoad is a Mojolicious production server with a prefork + asynchronous I / O implementation and performance optimized.

cd ~ / webapp
hypnotoad script / webapp
Web application available at http://127.0.0.1:8080

Port number 8080 is closed, so use the curl command on the command line to check. If "I? Mojolicious!" Is displayed, the production server has started correctly.

curl http://127.0.0.1:8080

Use the "--stop" option to stop.

hypnotoad script / webapp --stop

If you want to change the port number, you can change it with the listen option in the configuration file. The configuration file name is "webapp.conf".

Items required in the Mojolicious configuration file to connect to the reverse proxy

When connecting to a reverse proxy, at least the required items in the Mojolicious configuration file are required. ,It is less than.

If the configuration file is webapp.conf

If the setting file name is webapp.conf, add the following settings.

# webapp.conf
{
  hypnotoad => {proxy => 1}
};;

When the configuration file is webapp.yml

If the configuration file is webapp.yml, add the following settings. (Mojolicious 8.58 or later)

hypnotoad:
  proxy: 1

Let's check if it can be started with the above settings.

hypnotoad script / webapp

Connecting to a web application by reverse pixi from Apache

Please refer to the following for how to connect from Apache from a reverse proxy and publish a web application on the Internet.

Associated Information