前端web开发html如何避免js的跨域访问
今天开发几个页面,但是页面中调用了线上的一些http接口进行渲染页面,因为跨域问题,但是又不想弄成jsonp方式,因此弄个apache http server来折腾。这个只适用于linux
1.从apache下载apache httpd
2.下载安装后打开安装目录下conf文件夹的httpd.conf配置文件进行修改
3.首先修改Listen端口比如为8081,修改之后保存(因为可能默认的80端口被占用了,所以修改自己定义的)
Listen 8088
4.打开安装目录下bin文件夹的httpd启动
./httpd -X
5.打开浏览器输入localhost:8088,可以发现会出现It works!提示,这说明启动成功了
但是如果我需要换成我的一些静态html页面和js等,比如我有一个静态页面项目webapp,我放到/usr/local/apache2/webapp(当然自己可以指定放到其他目录)
那么再打开httpd.conf找到如下
DocumentRoot "/usr/local/apache2/htdocs" <Directory "/usr/local/apache2/htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn‘t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>
将/usr/local/apache2/htdocs替换为/usr/local/apache2/webapp
DocumentRoot "/usr/local/apache2/webapp" <Directory "/usr/local/apache2/webapp"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn‘t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>
保存后,重新启动httpd再访问即可正常访问其他了。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。