1
votes

I'm trying to run Dancer2 as a FastCGI script under Apache 2.4, as described here: https://metacpan.org/pod/Dancer2::Manual::Deployment#As-a-FastCGI-script

My /etc/apache2/sites-enabled/saltstrau.men.conf looks like this:

<VirtualHost *:80>
    ServerName   saltstrau.men
    DocumentRoot /var/www/me/MyApp/public

    FcgidWrapper /var/www/me/MyApp/public/dispatch.fcgi

    <Directory "/var/www/me/MyApp/public">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AddHandler fastcgi-script .fcgi
        Require all granted
        Header set Access-Control-Allow-Origin "*"
    </Directory>

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]

    CustomLog /var/log/apache2/saltstrau.men_access.log combined
    ErrorLog  /var/log/apache2/saltstrau.men_error.log
</VirtualHost>

And the Dancer2 webapp is the stock demo application, generated like this:

$ dancer2 gen -a MyApp

But when I point my laptop's brower to http://saltstrau.men/ instead of the "Perl is Dancing" page I get a webpage saying:

Not Found

The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at saltstrau.men Port 80

Note that this is not Dancer2's static .../MyApp/public/404.html page.

Question: How can I make Dancer2 work on port 80 on Apache 2.4?

Some failed attempts at solving this issue:

  1. Restarting Apache is required whenever making changes to Dancer, but Apache restarts have no effect on this issue (Neither does a server reboot)

  2. I did manage to serve static web pages (e.g. .../MyApp/public/404.html) on port 80 by commenting out these 3 lines:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]

, but that defeats the purpose because it stops Dancer2 from being called.

  1. I've verified that Dancer2 is correctly installed, and the stock demo webapp working, by testing them via plackup on the server:
$ sudo plackup /var/www/me/MyApp/bin/app.psgi
HTTP::Server::PSGI: Accepting connections at http://0:5000/
[MyApp:2307] core @2019-10-15 01:03:53> looking for get / in 
/usr/local/share/perl/5.26.1/Dancer2/Core/App.pm l. 36
[MyApp:2307] core @2019-10-15 01:03:53> Entering hook 
core.app.before_request in (eval 218) l. 1
[MyApp:2307] core @2019-10-15 01:03:53> Entering hook 
core.app.after_request in (eval 218) l. 1

When I now point my laptop's brower to http://saltstrau.men:5000/ I get the familiar "Perl is Dancing" page. And http://saltstrau.men:5000/404.html returns the static page located at ..../MyApp/public/404.html.

  1. In another attempt at debugging my configuration I even tried running the webapp stand-alone on port 80, but port 80 is already in use:
$ sudo plackup -p 80 /var/www/me/MyApp/bin/app.psgi
failed to listen to port 80: Address already in use at 
/usr/local/share/perl/5.26.1/HTTP/Server/PSGI.pm line 103.

My server was created a few days ago, so all SW versions are recent: Ubuntu 18.04, Apache 2.4.29 and Dancer2 0.208001. All required Apache modules are enabled:

/etc/apache2/mods-enabled$ ls 
access_compat.load  autoindex.load  include.load      setenvif.conf
alias.conf          deflate.conf    mime.conf         setenvif.load
alias.load          deflate.load    mime.load         socache_shmcb.load
auth_basic.load     dir.conf        mpm_event.conf    ssl.conf
authn_core.load     dir.load        mpm_event.load    ssl.load
authn_file.load     env.load        negotiation.conf  status.conf
authz_core.load     fcgid.conf      negotiation.load  status.load
authz_host.load     fcgid.load      reqtimeout.conf
authz_user.load     filter.load     reqtimeout.load
autoindex.conf      headers.load    rewrite.load
1
You have configured Apache to run FCGI but you are running your application as a separate daemon. You should configure Apache to proxy to your daemon, as described at metacpan.org/pod/….Grinnz
You are running your as an HTTP daemon, he means. (@Grinnz's statement was confusing because an FCGI app would have to be run as a daemon.)ikegami
I realize that mentioning plackup in my question gave the impression that I was trying to run the webapp stand-alone. I've now updated my question to reflect that I'm attempting to run Dancer2 as a FastCGI script under Apache. I also tweaked the heading.user12138447

1 Answers

1
votes

I initially thought I had solved this by changing

AddHandler fastcgi-script .fcgi

to

SetHandler fcgid-script

in my /etc/apache2/sites-enabled/saltstrau.men.conf.

, as shown in the "Configuration directives" example of the Apache doc: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples

However, that "solution" did not last long, so I gave up on starting Dancer2 as a fast CGI application.

SOLUTION: I ended up starting Dancer2 as a stand-alone daemon and using ProxyPass in my Apache configuration to forward requests to Dancer2. As suggested by comments above. This has been working reliably for days now.