如何在 nginx.conf 中指定一个目录来提供 index.html

dav*_*vid 4 nginx

我正在尝试重写一个非常简单的 nginx.conf 文件。该项目的唯一目的是让 nginx 在本地主机上提供静态 index.html。

由于所有在线文档和教程都有至少 50 行配置。我想知道我的 7 行配置是否可以工作并完成我需要的工作。

}    
  server {
    root /test/index
    listen 8888;
  }
}
Run Code Online (Sandbox Code Playgroud)

通常我只使用默认的 nginx.conf 并对我正在处理的任何项目进行修改,所以我不确定我是否可以像这里一样删除它并让它仍然起作用?

小智 5

您最好也包含 server_name,并以分号结束您的语句:

server {
    server_name some.server.name;
    listen 8888;
    # or just _ (underscore) to listen to any name
    root /test/index;
    index index.html;
}
Run Code Online (Sandbox Code Playgroud)