配置需求来自于前后端分离。后台由于使用PHP或者Java,但是前端使用vue,React这些框架时怎么和后端有效的数据通信。反向代理是个很好的选择,虽然jsonp也可以,单并不好玩。
-实际上线项目需要通过域名来访问,比如http://www.xxx.com,但在本机上如何配置虚拟域名来访问本机的项目呢?
1.找到C:\\Windows\\System32\\drivers\\etc\\hosts这个文件添加以下格式内容
?
|
1 |
127.0.0.1 www.mytest.com //你的虚拟域名 |
2.配置Apache项目目录
1.找到 \\apache\\conf\\httpd.conf 这个文件,修改内容
?
|
1
2 |
# Virtual hosts
Include conf/extra/httpd-vhosts.conf (这行的注释#去掉) |
2.找到\\apache\\conf\\extra\\httpd-vhosts.conf这个文件配置项目目录
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
<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为例
?
|
1
2
3
4
5
6
7
8
9 |
proxyTable: {
'/api': {
target: 'http://www.mytest.com/api',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}, |
这样就可以实现跨域访问了。
示例:
?
|
1
2
3
4
5
6
7
8 |
$.ajax({
url: '/api/indexList.php',
type: 'GET',
success: function (data) {
that.list = data.data;
console.log(data);
}
}) |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:http://blog.csdn.net/yy211zhu/article/details/68067638
相关文章
猜你喜欢
- 刀片服务器是什么 刀片服务器的主要特点 2025-05-27
- 利用FTP和计划任务自动备份网站数据和数据库 2025-05-27
- 服务器技术之硬件冗余技术 2025-05-27
- 服务器是租用还是服务器托管好? 2025-05-27
- 什么是DNS以及它如何影响服务器? 2025-05-27
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
单台服务器中利用Apache的VirtualHost如何搭建多个Web站点详解
2025-05-27 53 -
2025-05-27 85
-
2025-05-27 47
-
2025-05-25 109
-
2025-05-27 89
热门评论

