php - Cockpit CMS 安装后不会由 Apache 提供服务(404 错误)

标签 php apache ubuntu

我正在尝试让 Cockpit CMS ( https://getcockpit.com/documentation ) 在 Ubuntu 16.04 服务器上运行。文档是有限的。我已将 cockpit 文件夹放在我的 Apache 文档根目录中 /var/www/html/root/cms .

安装页面位于 website.com/cms/install工作。此页面现在重定向到 website.com/cms/auth/login找不到(404 错误)。 website.com/cms也重定向到 /cms/auth/login .

目录/var/www/html/root/cms/auth/login不存在(与本地相同)。一切都在使用 MAMP 的本地环境中工作,使用相同的目录结构。

Apache日志有以下错误,但我不认为它是相关的:
server certificate does NOT include an ID which matches the server name
我试过配置 Apache 并给出 /cms/指向目录的别名。我还更改了 /var/www/html/root/cms/ 的权限目录,以便所有文件都可读。

我尝试将 DocumentRoot 更改为 /var/www/html2/ .在这个目录中只有 cms文件夹。这并没有什么不同,在请求 website.com/cms/auth/login 时仍然会出现 404 错误。

我不认为这是一个依赖问题。 php版本是7.0。 PDO + SQLite 已安装。 php7.0-gd 已安装。 mod_rewrite 也被启用。

这是我启用站点的配置文件:

<VirtualHost *:80>
    Redirect / https://website.com/
</VirtualHost>
<VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/root
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info  SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
    SSLEngine on
        SSLCertificateFile /usr/local/ssl/crt/public.crt
        SSLCertificateKeyFile /usr/local/ssl/crt/website.key
        SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /alternate/ "/var/www/html/alternate/"
    <Directory "/var/www/html/alternate/">
    </Directory>
    Alias /root/ "/var/www/html/root/"
        <Directory "/var/www/html/root/">
    </Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

最佳答案

install/index.php确实存在于磁盘上,因此只要 Apache 和 PHP 正常工作,您无需任何特殊的服务器配置即可访问该文件。你就是这样到达那里的。

但是一旦安装,Cockpit 依赖于 .htaccess 中指定的重定向规则。路由 auth/login 之类的 URL ,磁盘上不存在的,到适当的真实文件进行处理。如果失败,则意味着重写规则不起作用,您需要进行设置。

首先,确保 mod_rewrite已启用。在 Ubuntu 上,您应该可以这样做:

sudo a2enmod rewrite

接下来,您需要确保 .htaccess文件处理已启用 - 如果未启用,.htaccess文件(如 Cockpit 目录中的文件)会被忽略。将以下部分添加到 VirtualHost您的虚拟主机配置 block (可能类似于 /etc/apache2/sites-available/website.conf ):
# The Directory should be where Cockpit's README.md is
<Directory "/var/www/html/root/cms"> 
    AllowOverride All
</Directory>

接下来,如评论中所述,删除 Alias es 和空 Directory您在虚拟主机配置中拥有的 block ,它们不是必需的,只会混淆事物。这是最终的配置文件:
<VirtualHost *:80>
    Redirect / https://website.com/
</VirtualHost>

<VirtualHost *:443>
    # Add your real, fully-qualified servername
    ServerName www.example.com

    ServerAdmin webmaster@localhost

    # The Directory should be where Cockpit's README.md is
    DocumentRoot /var/www/html/root/cms

    # The Directory should be where Cockpit's README.md is
    <Directory "/var/www/html/root/cms"> 
        AllowOverride All
    </Directory>

    SSLEngine on
        SSLCertificateFile /usr/local/ssl/crt/public.crt
        SSLCertificateKeyFile /usr/local/ssl/crt/website.key
        SSLCertificateChainFile /usr/local/ssl/crt/intermediate.crt
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

重新启动 Apache 以使这些更改生效:
sudo systemctl restart apache2

关于php - Cockpit CMS 安装后不会由 Apache 提供服务(404 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46696794/

相关文章:

php - 实体中的 Doctrine isDeletable 方法

Php文件显示空白页

php - 编译后未创建 libphp5.so 且未创建前缀目录

python - 如何修复 "No module named ' kivy._clock'"ubuntu 中的错误?

java - Ubuntu 没有这样的文件或目录

linux - 找出程序从哪里运行?

javascript - RSA 加密 : reproducing JS behaviour with PHP

php - PDF 生成不保留样式表

hosting - 间歇性完全渲染失败最终无法连接 - City_Magazine Theme

php - 通过ajax上传文件最终出现在php ://input中