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

What exactly is the nginx request_uri?

· 52CE 我爱测

I'm trying to understand the $request_uri variable in nginx configuration. The documentation says full original request URI (with arguments) To me that seems to be totally unambiguous - it should be the entire requested URI, incl…

问题原文

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

I'm trying to understand the $request_uri variable in nginx configuration. The documentation says

full original request URI (with arguments)

To me that seems to be totally unambiguous - it should be the entire requested URI, including the host and protocol. But in actual usage, it seems to only include the path & query arguments. Is there any authoritative source that says exactly what nginx considers to be a request_uri? I can't find any further references in the documentation, and I tried to get it out of the source code, but there are no comments and it's hard to understand the overall structure.

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

The Request-URI does not refer to the RFC 3986 URI, but is a term from RFC 2616, 5.1.2 HTTP/1.1 draft standard from 1999.

The Request-URI in RFC 2616 could have been any of:

Request-URI = "*" | absoluteURI | abs_path | authority

Here, the absoluteURI is equivalent with the RFC 3986 URI, and mainly used in HTTP proxys. Søren Løvborg explains in an answer on Stack Overflow why it is not necessary to have the full URI in this context:

In normal HTTP requests, the URL scheme and host have already been handled by the time the request is sent (and the URL fragment does not exist at the HTTP protocol level at all), meaning the Request-URI is a path-absolute-URL string, possibly followed by ? and a URL-query string.

Request-URI seems to be replaced with the (more unambiguous) term Request Target in RFC 7230, 3.1.1 proposed standard from 2014, where a Request Line...

begins with a method token, followed by a single space (SP), the request-target, another single space (SP), the protocol version, and ends with CRLF.

request-line = method SP request-target SP HTTP-version CRLF

The Request Target term is also used in the RFC 9110, 7.1 of the Internet Standard (June 2022); URI References are defined in RFC 9110, 4.1.

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

资料来源与适用范围

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

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

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