Dancer2
view release on metacpan or search on metacpan
lib/Dancer2/Manual/Deployment.pod view on Meta::CPAN
=head2 Using Server::Starter for Zero-Downtime Deployments
L<Server::Starter> provides you with a superdaemon and instance script
for managing PSGI-based Perl application servers. The superdaemon is
responsible for starting new processes and shutting down old ones. It
provides hot-deployment capability by watching for restart requests and
ensuring new processes successfully start up before terminating the old
processes. F<start_server> is the command-line program that allows you
to interact with the superdaemon.
You can manage most PSGI-based app server with F<start_server>:
start_server --port 5000 -- plackup -s Gazelle -a app.psgi
=head2 Using uWSGI
L<uWSGI|https://uwsgi-docs.readthedocs.io/en/latest/> is a robust
application server that supports PSGI. It is written in C and provides
excellent performance.
For configuring uWSGI with a Dancer2 application, refer to the official
documentation: L<https://uwsgi-docs.readthedocs.io/en/latest/Perl.html>.
A basic configuration might look like this:
uwsgi --http :5000 --plugin psgi --psgi bin/app.psgi
uWSGI is powerful and supports features like process management, load
balancing, and integration with NGINX.
=head1 Running Behind a Reverse Proxy
Using another webserver like NGINX to reverse proxy your application can
improve the scalability and security of your application. A reverse proxy
handles incoming requests, forwards them to your PSGI server, and manages
features like SSL termination and caching. Reverse proxies can help
improve the performance of your applications by serving static content
more efficiently than your application can.
When running your Dancer2 application behind a reverse proxy, make sure
to set the C<behind_proxy> configuration setting to make sure all URLs
and headers are set properly:
behind_proxy: 1
For more information, see L<the configuration guide|Dancer2::Manual::Config/behind_proxy (boolean)>.
=head2 Example: Using NGINX with Starman
Hereâs a basic NGINX configuration for a Dancer2 app running on Starman:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Start NGINX and Starman, and your app will be accessible through the proxy.
=head2 Example: Using NGINX with uWSGI
For uWSGI, the NGINX configuration looks like this:
server {
listen 80;
server_name example.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
}
}
This setup routes requests from NGINX to your uWSGI server.
=head1 Running Through CGI/FastCGI
While PSGI servers are recommended, Dancer2 can also run through CGI or
FastCGI, typically with Apache.
=head2 Running as a CGI Script
In a CGI setup, requests are processed one at a time, making it
unsuitable for high-traffic environments; a new instance of your
application is compiled and served on every request. To enable CGI:
=over 4
=item 1. Place your C<app.psgi> file in a directory accessible to your Apache server.
=item 2. Configure Apache to execute the PSGI script as a CGI:
=back
<VirtualHost *:80>
ServerName example.com
DocumentRoot /path/to/your/app/public
ScriptAlias / /path/to/your/app/bin/app.psgi
</VirtualHost>
=head2 Running as a FastCGI Script
FastCGI is a more efficient alternative to CGI. Install a PSGI-to-FastCGI adapter like C<FCGI::PSGI> and configure Apache:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /path/to/your/app/public
<Location />
SetHandler fcgid-script
Options +ExecCGI
FCGIWrapper /path/to/your/app/bin/app.psgi
</Location>
( run in 0.771 second using v1.01-cache-2.11-cpan-39bf76dae61 )