使用代理位置修复 Apache 虚拟主机

使用代理位置修复 Apache 虚拟主机

鉴于以下虚拟主机:

<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>

相关内容