Ubuntu Apache2 服务器不允许 CORS 或读取 .htaccess

Ubuntu Apache2 服务器不允许 CORS 或读取 .htaccess

我有几个问题,第一个是我的 apache2 服务器没有读取.htaccess

我的apache2.conf设置如下:

# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
</FilesMatch>

我启用了 mod_headersa2enmod headers

在 中.htaccess,我有:

Header set Access-Control-Allow-Origin "*"

当尝试通过 javascript 文件访问时,我得到:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

我补充道:

Header set Access-Control-Allow-Origin "*"

每次编辑时apache2.conf我都会重新启动 apache2service apache2 restart

apache2.conf它却给了我一个500 internal server error。我可以用浏览器访问该页面,但通过 javascript 却不能。我该怎么做才能解决这个问题?

答案1

事实证明我必须打开 mod_rewrite ( a2enmod rewrite) 并且 .php 文件有我看不到的错误,为此我使用了:

<?php
 error_reporting(E_ALL);
 ini_set("display_errors", 1);
 include("file_with_errors.php");
?>

来自 php 手册站点,此页面:http://www.php.net//manual/en/function.error-reporting.php

另外,如果您想一直打开错误报告(我就是这么做的),请php.ini按如下方式更改以下内容:

display_errors = Off

-到-

display_errors = On

非常理想。

相关内容