![使用代理位置修复 Apache 虚拟主机](https://linux22.com/image/638348/%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%90%86%E4%BD%8D%E7%BD%AE%E4%BF%AE%E5%A4%8D%20Apache%20%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA.png)
鉴于以下虚拟主机:
<VirtualHost *:80>
DocumentRoot "/var/www/dashboards/public/dist"
Servername local.dashboards
ServerAlias local.dashboards
Header add Access-Control-Allow-Origin: "*"
Header add Access-Control-Allow-Methods: "POST, GET, OPTIONS, PUT, DELETE, HEAD"
Header set Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept, Authorization"
Alias /api /var/www/dashboards/laravel/public
<Directory "/var/www/dashboards/public/dist">
Options MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/var/www/dashboards/laravel/public">
Options MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Location />
ProxyPass http://localhost:3030/
ProxyPassReverse http://localhost:3030/
</Location>
ErrorLog ${APACHE_LOG_DIR}/dashboards.error.log
CustomLog ${APACHE_LOG_DIR}/dashboards.access.log combined
</VirtualHost>
有人能解释一下为什么对 local.dashboards/api 的请求仍然被 Location 指令捕获吗?我可以确认节点服务器正在捕获对 /api 的请求并返回 404 页面。
答案1
来自文档:
别名在
<Directory>
检查部分之前发生,因此只有别名的目标会受到影响。(但请注意,<Location>
在执行别名之前部分会运行一次,因此它们将适用。)
A<Location />
几乎适用于所有事物。
那怎么样<LocationMatch !^/api>
?