【问题标题】:Apache stops serving static pages when the FastCGI application Dancer2 is enabled启用 FastCGI 应用程序 Dancer2 时,Apache 停止提供静态页面
【发布时间】:2020-02-12 02:27:46
【问题描述】:

我正在尝试在 Apache 2.4 下将 Dancer2 作为 FastCGI 脚本运行,如下所述:https://metacpan.org/pod/Dancer2::Manual::Deployment#As-a-FastCGI-script

我的 /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>

Dancer2 webapp 是股票演示应用程序,生成如下:

$ dancer2 gen -a MyApp

但是当我将笔记本电脑的浏览器指向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

请注意,这不是 Dancer2 的静态 .../MyApp/public/404.html 页面。

问题:如何让 Dancer2 在 Apache 2.4 的 80 端口上工作?

解决此问题的一些失败尝试:

  1. 每当对 Dancer 进行更改时都需要重新启动 Apache,但重新启动 Apache 对这个问题没有影响(服务器也不会重新启动)

  2. 我确实设法在 通过注释掉这 3 行来端口 80:

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

,但这违背了目的,因为它阻止了 Dancer2 被调用。

  1. 我已通过服务器上的 plackup 对其进行测试,验证了 Dancer2 已正确安装,并且股票演示 web 应用程序正常运行:
$ 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

当我现在将笔记本电脑的浏览器指向http://saltstrau.men:5000/ 我得到了熟悉的“Perl is Dancing”页面。 http://saltstrau.men:5000/404.html 返回位于 ..../MyApp/public/404.html 的静态页面。

  1. 在调试配置的另一次尝试中,我什至尝试在端口 80 上独立运行 webapp,但端口 80 已在使用中:
$ 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.

我的服务器是几天前创建的,所以所有软件版本都是最新的:Ubuntu 18.04、Apache 2.4.29 和 Dancer2 0.208001。已启用所有必需的 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

【问题讨论】:

  • 您已将 Apache 配置为运行 FCGI,但您将应用程序作为单独的守护程序运行。您应该将 Apache 配置为代理到您的守护程序,如 metacpan.org/pod/… 所述。
  • 你是作为一个 HTTP 守护进程运行的,他的意思是。 (@Grinnz 的声明令人困惑,因为 FCGI 应用程序必须作为守护程序运行。)
  • 我意识到在我的问题中提到 plackup 给人的印象是我试图独立运行 webapp。我现在更新了我的问题,以反映我正在尝试在 Apache 下将 Dancer2 作为 FastCGI 脚本运行。我还调整了标题。

标签: apache perl


【解决方案1】:

我最初以为我已经通过更改解决了这个问题

AddHandler fastcgi-script .fcgi

SetHandler fcgid-script

在我的 /etc/apache2/sites-enabled/saltstrau.men.conf 中。

,如Apache文档的“配置指令”示例所示:http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#examples

但是,这个“解决方案”并没有持续多久,所以我放弃了将 Dancer2 作为快速 CGI 应用程序启动。

解决方案:我最终将 Dancer2 作为一个独立的守护进程启动,并在我的 Apache 配置中使用 ProxyPass 将请求转发到 Dancer2。正如上面的 cmets 所建议的那样。这已经可靠地工作了好几天了。

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 2018-11-08
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2015-06-22
    • 1970-01-01
    相关资源
    最近更新 更多