0

我正在使用 Windows 并使用 Winginx,修改 conf 文件夹下的 nginx.conf 文件。我已经改变了监听端口的服务器块,如下所示:

server{
 listen 127.0.0.1:80;
 log_not_found off;
 charset utf-8;

 access_log logs/access.log main;

 location /images/ {
  root home/localhost/public_html;
  index index.php index.html;
 }
}

images 文件夹位于 winginx 的主文件夹下,通过 hostseditor 添加为域。但是,当我使用 URL 时http://images,出现 404 错误。

如果位置指令更改为:

location / {
}

那时一切正常。除非我匹配“/”,否则任何正则表达式都不起作用。我已阅读位置指令,但找不到任何相关原因。如果有人能指出错误,那将是很大的帮助。谢谢。

4

1 回答 1

2

原因是该location指令匹配 URI(更准确地说是 Request-URI 的绝对路径),而不是 Host。

当您使用 时http://images,您的浏览器会发送如下请求:

GET / HTTP/1.1
Host: images

请注意,请求 URI 是/.

于 2013-08-07T11:06:47.317 回答