这是我的配置文件。
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost:80
DocumentRoot /var/www/XXX
<Directory />
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory /var/www/qvbn-app-web-ctrl>
Options FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
Header set Access-Control-Allow-Origin "*"
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
字符串
当我尝试重新加载apache2时,iT给出错误:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
型
我不知道如何启用CORS。我跟着这个:http://enable-cors.org/server_apache.html
9条答案
按热度按时间x6h2sr281#
字符串
修改/etc/apache 2/apache2.conf
型
添加/激活模块
型
重新启动服务
型
nvbavucw2#
首先在服务器上启用
mod_headers
,然后您可以在Apache conf和.htaccess
中使用header指令。1.启用
mod_headers
a2enmod headers
个1.配置
.htaccess
文件中的头字符串
8iwquhpp3#
在httpd.conf中
1.确保这些已加载:
字符串
1.在目标目录中:
型
qco9c6ql4#
将以下内容放入站点的.htaccess文件中(位于/var/www/XXX中):
字符串
而不是.conf文件。
您还将需要使用
型
在您的.conf文件中,以便Apache查看。
xu3bshqb5#
Ubuntu Apache 2解决方案对我有效。htaccess编辑对我不起作用,我不得不修改conf文件。
nano /etc/apache2/sites-available/mydomain.xyz.conf
我的配置工作,以允许CORS支持
字符串
然后输入以下命令
a2 enmod标头
尝试前确保缓存已清空
yyhrrdl86#
在Apache2中启用mod_headers,以便能够使用Header指令:
字符串
zwghvu4y7#
我费了很大劲才让它起作用。别忘了,即使是子请求,旧页面也会缓存在浏览器中。也许很明显,但请清除浏览器的缓存。之后,还可以使用
Header set Cache-Control "no-store"
这对我在测试时很有帮助。mdfafbf18#
FWIW,在标准共享服务器托管配置(Namecheap)上-在不需要安全性的非生产帐户上-这对我来说很有效:
字符串
qjp7pelc9#
你也可以把下面的代码放到htaccess文件中,以允许CORS使用htaccess文件
字符串
为了信息的目的,你也可以看看这篇文章http://www.ipragmatech.com/enable-cors-using-htaccess/允许CORS头.