Apache虛擬目錄配置及vue-cli反向代理的設(shè)置方法
配置需求來自于前后端分離。后臺由于使用PHP或者Java,但是前端使用vue,React這些框架時怎么和后端有效的數(shù)據(jù)通信。反向代理是個很好的選擇,雖然jsonp也可以,單并不好玩。
Apache配置虛擬目錄
-實際上線項目需要通過域名來訪問,比如http://www.xxx.com,但在本機上如何配置虛擬域名來訪問本機的項目呢?
1.找到C:\Windows\System32\drivers\etc\hosts這個文件添加以下格式內(nèi)容
127.0.0.1 www.mytest.com //你的虛擬域名
2.配置Apache項目目錄
1.找到 \apache\conf\httpd.conf 這個文件,修改內(nèi)容
# Virtual hosts Include conf/extra/httpd-vhosts.conf (這行的注釋#去掉)
2.找到\apache\conf\extra\httpd-vhosts.conf這個文件配置項目目錄
<VirtualHost *:80>
##ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/mobileApp" ##你的后端項目目錄
ServerName www.mytest.com ##虛擬域名
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
<Directory "C:/xampp/htdocs/mobileApp">
Options Indexes FollowSymLinks
DirectoryIndex index.html index.php
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3.proxyTable代理配置,以vue-cli為例
proxyTable: {
'/api': {
target: 'http://www.mytest.com/api',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
這樣就可以實現(xiàn)跨域訪問了。
示例:
$.ajax({
url: '/api/indexList.php',
type: 'GET',
success: function (data) {
that.list = data.data;
console.log(data);
}
})
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于python的Linux系統(tǒng)指定進程性能監(jiān)控思路詳解
這篇文章主要介紹了基于python的Linux系統(tǒng)指定進程性能監(jiān)控的思路詳解,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09
Linux解決RocketMQ中NameServer啟動問題的方法詳解
這篇文章主要為大家詳細介紹了Linux解決RocketMQ中NameServer啟動問題的方法,文中通過圖片和示例代碼進行了詳細講解,需要的小伙伴可以參考下2023-08-08
linux系統(tǒng)中通過rsync+inotify實現(xiàn)網(wǎng)頁自動同步
這篇文章主要介紹了linux系統(tǒng)中通過rsync+inotify實現(xiàn)網(wǎng)頁自動同步,需要的朋友可以參考下2014-11-11

