apache虚拟主机配置反向代理,解决跨域请求的问题
1,修改apache配置文件:http.conf,解注释以下内容:
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so
2,打开虚拟主机配置文件vhosts.conf,找到要配置的虚拟主机段,
如配置:www.fastorder.com/api,指向api.fastorder.com ,内容如下:
<VirtualHost *:80> DocumentRoot "D:\phpStudy\WWW\fastadmin\public" ServerName www.fastorder.com <Directory "D:\phpStudy\WWW\fastadmin\public"> Options FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> #反向代理设置 ProxyRequests Off ProxyPass /api http://api.fastorder.com ProxyPassReverse /api http://api.fastorder.com </VirtualHost>
总结:这样当前端页面打包部署在www.fastorder.com下,请求接口www.fastorder.com/api/* 即可,便不会产生跨域问题。