AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 467654
Accepted
scrapy
scrapy
Asked: 2018-09-08 17:22:11 +0800 CST2018-09-08 17:22:11 +0800 CST 2018-09-08 17:22:11 +0800 CST

如何为选项请求制作 httpd 响应 200?

  • 772

我想在我的 centos+apache 上进行一些配置,让 httpd 服务器在客户端发出选项请求时发送 200 响应。

这里有一篇很老的帖子(2011)。

在 Apache 中对 HTTP OPTIONS 请求返回“200 OK”

该配置可能不适合当前的操作系统和 apache。

如果配置状态良好,curl -X OPTIONS -i http://remote_ip/remote.html可能会得到 200 返回码。

这是我的尝试:

1.cat .htaccess

AuthName "login"  
AuthType Basic  
AuthUserFile /var/www/html/passwd  
require user usernam
Options -Indexes
<LimitExcept OPTIONS>
  Require valid-user
</LimitExcept>

systemctl restart httpd使用命令的 .Error 信息重新启动它:curl -X OPTIONS -i http://remote_ip/remote.html

<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>

删除 .htacccess 中的上述配置。

2.cat /etc/httpd/conf/httpd.conf。

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride AuthConfig
    Require all granted
    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Access-Control-Allow-Headers "Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With"
    RewriteEngine On                  
    RewriteCond %{REQUEST_METHOD} OPTIONS 
    RewriteRule ^(.*)$ blank.html [QSA,L]
</Directory>

systemctl restart httpd使用命令的 .Error 信息重新启动它:curl -X OPTIONS -i http://remote_ip/remote.html

HTTP/1.1 401 Unauthorized
Date: Sat, 08 Sep 2018 00:34:36 GMT
Server: Apache/2.4.6 (CentOS)
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With
WWW-Authenticate: Basic realm="login"
Content-Length: 381
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
centos apache-httpd
  • 2 2 个回答
  • 3460 Views

2 个回答

  • Voted
  1. Best Answer
    mhutter
    2018-09-12T15:46:16+08:002018-09-12T15:46:16+08:00

    首先,您的.htaccess文件存在问题:

    • 在第 6-8 行;您需要对用户进行身份验证,但前提是它不是OPTIONS请求。这可以。
    • 但是,在第 4 行中,您需要将用户身份验证为 user usernam,而不管请求方法(GET、POST、OPTIONS 等...)

    因此,如果您删除第 4 行或将其移动到LimitExcept您的配置应该工作的部分。

    有关更多信息,请参阅mod_authz_core 文档


    其次,您发布的第一个解决方案的错误消息(“服务器遇到内部错误或配置错误......”)提示httpd.conf文件无效。可能还有其他错误配置。检查您的配置和Apache 文档。


    作为参考,我用于测试的配置文件可以在以下位置找到:https ://github.com/mhutter/stackexchange/tree/master/467654

    • 3
  2. RalfFriedl
    2018-09-12T22:03:48+08:002018-09-12T22:03:48+08:00

    该错误401 Unauthorized意味着 HTTP 服务器需要凭据,通常是用户名和密码。根据问题,您删除了.htacccess请求身份验证的文件,因此在活动配置中必须仍然存在请求身份验证的内容。

    要提供凭据,curl您可以使用选项-u, --user <user:password>(短格式或长格式)。


    当您收到错误500时,Apache 日志中应该有一个条目来解释发生了什么错误。


    当某些东西不起作用时,通常最好将配置减少到所需的最小值以找到问题。为此,请注释掉您认为不会导致问题的行,然后重试。要么它开始工作,然后你知道在哪里更仔细地观察,要么你有一个简化的配置。

    使用您的配置,标题行可能不会导致问题,但我会首先尝试在没有重定向的情况下使其正常工作。当你有一个工作配置时,你可以添加行直到它再次中断或者你有你想要的配置。

    • 0

相关问题

  • smartmontools - 自动测试是否与运行简短测试相同?

  • systemctl 命令在 RHEL 6 中不起作用

  • 为什么我的交换机没有从指定的池中获取地址

  • 在 CentOS7 GNOME 的 Applications-menu 选项卡中创建自定义菜单

  • 奇怪的路由器与centos 6一起工作[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve