前端web开发html如何避免js的跨域访问

今天开发几个页面,可是页面中调用了线上的一些http接口进行渲染页面,由于跨域问题,可是又不想弄成jsonp方式,所以弄个apache http server来折腾。这个只适用于linuxhtml

1.从apache下载apache httpdjava

2.下载安装后打开安装目录下conf文件夹的httpd.conf配置文件进行修改linux

3.首先修改Listen端口好比为8081,修改以后保存(由于可能默认的80端口被占用了,因此修改本身定义的)web

Listen 8088

4.打开安装目录下bin文件夹的httpd启动apache

./httpd -X

5.打开浏览器输入localhost:8088,能够发现会出现It works!提示,这说明启动成功了json

可是若是我须要换成个人一些静态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/webappapp

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再访问便可正常访问其余了。
webapp

相关文章
相关标签/搜索