Ubuntu——apache如何解决跨域资源访问

参考文档:http://blog.csdn.net/ownfire/article/details/46707229


1.sudo cd /etc/apache2/sites-available/
2. sudogedit000-default.conf
编辑添加 LoadModuleheaders_modulemodules/mod_headers.so

HeadersetAccess-Control-Allow-Origin*

如下:

<VirtualHost*:80>
LoadTileConfigFile/usr/local/etc/renderd.conf
ModTileRenderdSocketName/var/run/renderd/renderd.sock
LoadModuleheaders_modulemodules/mod_headers.so
#Timeoutbeforegivingupforatiletoberendered
ModTileRequestTimeout0
#Timeoutbeforegivingupforatiletoberenderedthatisotherwisemissing
ModTileMissingRequestTimeout30
#TheServerNamedirectivesetstherequestscheme,hostnameandportthat
#theserverusestoidentifyitself.Thisisusedwhencreating
#redirectionURLs.Inthecontextofvirtualhosts,theServerName
#specifieswhathostnamemustappearintherequest'sHost:headerto
#matchthisvirtualhost.Forthedefaultvirtualhost(thisfile)this
#valueisnotdecisiveasitisusedasalastresorthostregardless.
#However,youmustsetitforanyfurthervirtualhostexplicitly.
#ServerNamewww.example.com

ServerAdminwebmaster@localhost
DocumentRoot/var/www/html
HeadersetAccess-Control-Allow-Origin*

#Availableloglevels:trace8,...,trace1,debug,info,notice,warn,
#error,crit,alert,emerg.
#Itisalsopossibletoconfiguretheloglevelforparticular
#modules,e.g.
#LogLevelinfossl:warn

ErrorLog${APACHE_LOG_DIR}/error.log
CustomLog${APACHE_LOG_DIR}/access.logcombined

#Formostconfigurationfilesfromconf-available/,whichare
#enabledordisabledatagloballevel,itispossibleto
#includealineforonlyoneparticularvirtualhost.Forexamplethe
#followinglineenablestheCGIconfigurationforthishostonly
#afterithasbeengloballydisabledwith"a2disconf".
#Includeconf-available/serve-cgi-bin.conf
</VirtualHost>

#vim:syntax=apachets=4sw=4sts=4srnoet

3.重启Apache
serviceapache2restart
测试跨域访问即可

相关文章

ubuntu退出redis的示例:指定配置文件方式启动源码redis:roo...
ubuntu中mysql改密码忘了的解决方法:1.在终端中切换到root权...
ubuntu安装mysql失败的解决方法原因:可能是原有的MySQL还有...
使用centos和ubuntu建站的区别有以下几点1.CentOS是Linux发行...
ubuntu图形界面和字符界面切换的方法:可以通过快捷键CTRL+A...
ubuntu中重启mysql失败的解决方法1.首先,在ubuntu命令行中,...