[英]Apache stops serving static pages when the FastCGI application Dancer2 is enabled
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我正在尝试在 Apache 2.4 下将 Dancer2 作为 FastCGI 脚本运行,如下所述: https://metacpan.org/pod/Dancer2::Manual::Deployment#As-a-FastCGI-script
My /etc/apache2/sites-enabled/saltstrau.men.conf looks like this:我的 /etc/apache2/sites-enabled/saltstrau.men.conf 看起来像这样:
<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 webapp 是股票演示应用程序,生成如下:
$ 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:但是当我将笔记本电脑的浏览器指向http://saltstrau.men/而不是“Perl is Dancing”页面时,我看到一个网页说:
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.请注意,这不是 Dancer2 的 static.../MyApp/public/404.html 页面。
Question: How can I make Dancer2 work on port 80 on Apache 2.4?问:如何让 Dancer2 在 Apache 2.4 的 80 端口上工作?
Some failed attempts at solving this issue:解决此问题的一些失败尝试:
Restarting Apache is required whenever making changes to Dancer, but Apache restarts have no effect on this issue (Neither does a server reboot)每当对 Dancer 进行更改时,都需要重新启动 Apache,但 Apache 重新启动对此问题没有影响(服务器也不会重新启动)
I did manage to serve static web pages (eg .../MyApp/public/404.html) on port 80 by commenting out these 3 lines:通过注释掉这 3 行,我确实设法在端口 80 上为 static web 页面(例如 .../MyApp/public/404.html)提供服务:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /dispatch.fcgi$1 [QSA,L]
, but that defeats the purpose because it stops Dancer2 from being called. ,但这违背了目的,因为它阻止了 Dancer2 被调用。
$ 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.当我现在将笔记本电脑的浏览器指向http://saltstrau.men:5000/ 时,我看到了熟悉的“Perl is Dancing”页面。 And http://saltstrau.men:5000/404.html returns the static page located at..../MyApp/public/404.html.
And http://saltstrau.men:5000/404.html returns the static page located at..../MyApp/public/404.html.
$ 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.我的服务器是几天前创建的,所以所有的软件版本都是最新的:Ubuntu 18.04、Apache 2.4.29 和 Dancer2 0.208001。 All required Apache modules are enabled:
启用所有必需的 Apache 模块:
/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
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.在我的 /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 ,如 Apache 文档的“配置指令”示例所示: http://httpd.apache.org/mod_fcgid/
However, that "solution" did not last long, so I gave up on starting Dancer2 as a fast CGI application.然而,这个“解决方案”并没有持续多久,所以我放弃了将 Dancer2 作为快速 CGI 应用程序启动。
SOLUTION: I ended up starting Dancer2 as a stand-alone daemon and using ProxyPass in my Apache configuration to forward requests to Dancer2.解决方案:我最终将 Dancer2 作为独立守护程序启动,并在我的 Apache 配置中使用 ProxyPass 将请求转发到 Dancer2。 As suggested by comments above.
正如上面的评论所建议的那样。 This has been working reliably for days now.
这已经可靠地工作了好几天了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.