前端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

相關文章
相關標籤/搜索