【问题标题】:location directives confusion in nginx configurationnginx 配置中的位置指令混淆
【发布时间】:2013-07-30 09:26:02
【问题描述】:

我想在 nginx 配置中为 url "localhost/test/" 设置一个位置指令。

我在配置文件中尝试了以下内容:

server {
listen 80;
server_name localhost;
location /test/ {
root /home/test;
index index.html index.htm
}

}

这总是给我一个 404 错误。然后我尝试了这个

server {
listen 80;
server_name localhost;
location / {
root /home/test;
index index.html index.htm
}

}

它在 url "localhost" 上运行良好

我不明白为什么它在第一种情况下会抛出 404 错误!

【问题讨论】:

  • 你试过 localhost/test,去掉最后的'/'吗?
  • 你能在 /test/ 案例中将 root 设为别​​名并更新我吗
  • 不一样!!
  • 我使用了位置 /test/ { 别名 /home/test;索引 index.html index.htm }
  • 您添加虚拟 / 并尝试在 /test/ 中使用 root。

标签: nginx


【解决方案1】:

配置的一个明显问题是必须使用别名而不是 root

location /test/ {
    alias /home/test/;
}

因为,root 让 nginx 根据您的配置搜索 /home/test/test。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-09
    • 2012-11-09
    • 2014-02-15
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 2012-04-22
    • 2020-10-17
    相关资源
    最近更新 更多