如何配置nginx静态文

如何配置nginx静态文
最新回答
玖梦

2026-03-24 08:00:41

假设我们的静态文件位于 /Users/bowen 目录下,文件服务基本配置如下:
server {
client_max_body_size 4G;
listen 0.0.0.0:8888; ## listen for ipv4; this line is default and implied
server_name localhost;
root /Users/bowen/;
location / {
}
}12345678

location指令用来映射请求到本地文件系统。
root 指令用来指定文件在服务器上的基路径。
配置索引
server {
client_max_body_size 4G;
listen 8889; ## listen for ipv4; this line is default and implied
server_name localhost;
root /Users/bowen;
location / {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
}1234567891011

执行sudo nginx -s reload重新加载配置。在浏览器中访问
http://127.0.0.1:8889/
,即可显示root指定的/Users/bowen目录下的内容。