前端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再访问即可正常访问其他了。


转载于:https://my.oschina.net/kittyMan/blog/363491

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值