解决跨域问题

首先声明下,这种方法非常不好,但是由于只用在个人的实验性项目中,为了方便采取这种方式,后面会用另外的方式解决

1. 问题

journey.404mzk.com中调用inner.journey.404mzk.com会出现跨域问题,浏览器会报错

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

2. 解决

改一下apache.conf

原本

<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory>

改为

<Directory />
        Options FollowSymLinks
        Require all denied
        Header set Access-Control-Allow-Origin *
        #AllowOverride All
        #Require all denied
</Directory>

这样设置Header需要引入mod_headers模块

不然启动时,会报

AH00526: Syntax error on line 156 of /etc/apache2/apache2.conf:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
Action 'restart' failed.

引入mod_headers

/etc/apache2/mods-enabled# ln -s ../mods-available/headers.load ./

完事~.

参考链接

http://www.jb51.net/article/60084.htm

© 404mzk all right reserved,powered by Gitbookhttp://blog.404mzk.com 该文件修订时间: 2018-03-04 10:52:38

results matching ""

    No results matching ""