修改httpd.conf
<VirtualHost *:80>
ServerName app.taotianyue.com
DocumentRoot /data/web/guanwang_app/static_src
ErrorLog /data/web/guanwang_app/apache_error.log
ServerAdmin 346126185@.qq.com
Header set Access-Control-Allow-Origin *
ProxyRequests Off
ProxyPreserveHost On
ProxyPassMatch /*.jpg !
ProxyPassMatch /*.mp4 !
ProxyPassMatch /*.css !
ProxyPassMatch /*.gif !
ProxyPassMatch /*.png !
ProxyPassMatch /*.js !
ProxyPassMatch /*.html$ !
ProxyPass /test.html !
ProxyPass /index.html !
ProxyPassMatch ^/$ !
ProxyPass / http://127.0.0.1:8123/
ProxyPassReverse / http://127.0.0.1:8123/
<Directory "/data/web/guanwang_app/static_src">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.html
</Directory>
</VirtualHost>
说明
<VirtualHost *:80>
ServerName app.gaotianyue.com #域名
DocumentRoot /data/web/guanwang_app/static_src #静态资源目录
ErrorLog /data/web/guanwang_app/apache_error.log
ServerAdmin 346126185@qq.com
Header set Access-Control-Allow-Origin * #允许跨域
ProxyRequests Off
ProxyPreserveHost On
ProxyPassMatch /*.jpg !
ProxyPassMatch /*.mp4 !
ProxyPassMatch /*.css !
ProxyPassMatch /*.gif !
ProxyPassMatch /*.png !
ProxyPassMatch /*.js !
ProxyPassMatch /*.html$ ! #ProxyPassMatch 允许通配符
ProxyPass /test.html ! #ProxyPass不允许通配符
ProxyPassMatch ^/$ ! # 仅仅匹配 / ,而不匹配任何字符,这样使得访问域名绕过反向代理而使默认主页的设置不失效
ProxyPass / http://127.0.0.1:8123/
ProxyPassReverse / http://127.0.0.1:8123/
<Directory "/data/web/guanwang_app/static_src">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.html 默认主页
</Directory>
</VirtualHost>
为了更直观些,我截了个图
现在有种情况要对 /mg/文件夹下的html,css等资源也同样代理,但是其他的html,css等不代理,则么做?
添加
ProxyPassMatch /mg/ http://127.0.0.1:8123/
即可
<VirtualHost *:80>
ServerName app.sincetimes.com
DocumentRoot /data/web/guanwang_app/static_src
ErrorLog /data/web/guanwang_app/apache_error.log
Header set Access-Control-Allow-Origin *
ProxyRequests Off
ProxyPreserveHost On
ProxyPassMatch /mg/ http://127.0.0.1:8123/
ProxyPassMatch /*.jpg !
ProxyPassMatch /*.mp4 !
ProxyPassMatch /*.css !
ProxyPassMatch /*.gif !
ProxyPassMatch /*.png !
ProxyPassMatch /*.js !
ProxyPassMatch /*.html$ !
ProxyPass /test.html !
ProxyPass /index.html !
ProxyPassMatch ^/$ !
ProxyPass / http://127.0.0.1:8123/
ProxyPassReverse / http://127.0.0.1:8123/
<Directory "/">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
Header set Access-Control-Allow-Origin *
DirectoryIndex index.html
</Directory>
</VirtualHost>