禁止 Apache 别名
Apache Alias forbidden
我目前正在尝试在子文件夹中启动新版本的网络平台,以便它可以与现有平台共存。
例如
https://subdomain.example.com/ <-- 当前版本
https://subdomain.example.com/v3/ <-- 新版本
当前版本是 angularJS 应用,新版本是 Vuejs。该平台使用弹性 beantalk 托管在 AWS 上。
我现在的 apache 配置是
<VirtualHost *:80>
DocumentRoot "/var/app/current/current-app/releases/current"
<Directory "/var/app/current/current-app/releases/current">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} \.html$ [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.php
</Directory>
Alias "/v3" "/var/app/current/new-app/v3/"
AliasMatch "^/v3/(.*)$" "/var/app/current/new-app/v3/"
<Directory "/var/app/current/new-app/v3">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /v3/index.html [L]
</Directory>
</VirtualHost>
新应用程序编译到名为 v3
的文件夹中。
偶尔,当我访问 https://subdomain.example.com/v3/
时,我会看到新版本的网络应用程序。其他时候我会收到 403 错误。
任何时候我尝试直接去一个需要用vuejs路由器(v3
)处理的路由,apache returns一个403。例如https://subdomain.example.com/v3/auth/login.
但是,访问 /v3/ 本身会将我转到 /v3/auth/login 并显示正确的内容。
另一个问题是 https 的重写不再起作用并允许非 https 连接。
如有任何帮助,我们将不胜感激!
首先你想在使用重写规则时禁用MultiViews
。
您可能也想禁用自动索引,所以那将是 Options -Indexes +FollowSymLinks -MultiViews
.
因为你有一个重写规则,你实际上可以完全避免别名并重写到完整路径。这将使事情更容易管理。
类似于:
RewriteRule v3.*$ /var/app/current/new-app/v3/index.html [L]
该规则需要存在于您的 "main"(与您的 DocumentRoot
相关的东西)Directory
指令中,因为您不会像您一样访问实际的 v3 路径本身使用您的别名。
一个常见的误解是重写规则的重写部分应该是有效的 URL,而它可能只是一个有效的服务器路径。这里有一个有趣的观点:
Force a URL-path for mod_rewrite's RewriteRule Substitution
HTH
我目前正在尝试在子文件夹中启动新版本的网络平台,以便它可以与现有平台共存。
例如
https://subdomain.example.com/ <-- 当前版本
https://subdomain.example.com/v3/ <-- 新版本
当前版本是 angularJS 应用,新版本是 Vuejs。该平台使用弹性 beantalk 托管在 AWS 上。
我现在的 apache 配置是
<VirtualHost *:80>
DocumentRoot "/var/app/current/current-app/releases/current"
<Directory "/var/app/current/current-app/releases/current">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} \.html$ [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.php
</Directory>
Alias "/v3" "/var/app/current/new-app/v3/"
AliasMatch "^/v3/(.*)$" "/var/app/current/new-app/v3/"
<Directory "/var/app/current/new-app/v3">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /v3/index.html [L]
</Directory>
</VirtualHost>
新应用程序编译到名为 v3
的文件夹中。
偶尔,当我访问 https://subdomain.example.com/v3/
时,我会看到新版本的网络应用程序。其他时候我会收到 403 错误。
任何时候我尝试直接去一个需要用vuejs路由器(v3
)处理的路由,apache returns一个403。例如https://subdomain.example.com/v3/auth/login.
但是,访问 /v3/ 本身会将我转到 /v3/auth/login 并显示正确的内容。
另一个问题是 https 的重写不再起作用并允许非 https 连接。
如有任何帮助,我们将不胜感激!
首先你想在使用重写规则时禁用MultiViews
。
您可能也想禁用自动索引,所以那将是 Options -Indexes +FollowSymLinks -MultiViews
.
因为你有一个重写规则,你实际上可以完全避免别名并重写到完整路径。这将使事情更容易管理。
类似于:
RewriteRule v3.*$ /var/app/current/new-app/v3/index.html [L]
该规则需要存在于您的 "main"(与您的 DocumentRoot
相关的东西)Directory
指令中,因为您不会像您一样访问实际的 v3 路径本身使用您的别名。
一个常见的误解是重写规则的重写部分应该是有效的 URL,而它可能只是一个有效的服务器路径。这里有一个有趣的观点: Force a URL-path for mod_rewrite's RewriteRule Substitution
HTH