大网数据广告活动
服务器运维问答

Disabling (Apache) Basic Authentication for OPTIONS requests

· 52CE 我爱测

I have Apache basic authentication enabled on a test server and it works great: AuthType Basic AuthName "testing" AuthUserFile /home/www/.htpasswd Require user MyUser deny from all But it is also trying to authenticate requests s…

问题原文

原帖链接 · GIS-Jonathan · CC BY-SA 4.0

I have Apache basic authentication enabled on a test server and it works great:

AuthType Basic
AuthName "testing"
AuthUserFile /home/www/.htpasswd
Require user MyUser

deny from all

But it is also trying to authenticate requests sent via the OPTIONS method. Which is a problem because the CORS specification says that you should Exclude user credentials - https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0

How do I disable authentication for requests coming in with the OPTIONS method?

(Similar to this for Tomcat: Disable authentication for OPTIONS requests in Tomcat )

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

You can perhaps use an Apache expression (Apache 2.4+) to only apply the HTTP Basic Auth directives when the request method is not "OPTIONS".

For example:

<If "%{REQUEST_METHOD} != 'OPTIONS'">
# Authentication directives...
</If>

Reference:

https://httpd.apache.org/docs/2.4/expr.html

deny from all

You shouldn't need to use this (Apache 2.2) directive with your Basic Auth directives.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-06-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。