nginx

nginx怎么挂载文件目录

小亿
217
2024-02-27 09:29:56
栏目: 编程语言

要在nginx中挂载文件目录,需要在nginx的配置文件中添加一个location指令来指定需要挂载的文件目录。

例如,如果要挂载一个名为"files"的文件目录,可以在nginx的配置文件中添加如下配置:

server {
    listen 80;
    server_name example.com;

    location /files {
        alias /path/to/files/directory;
    }
}

在上面的配置中,当访问http://example.com/files时,nginx会将请求映射到/path/to/files/directory目录下的文件。

需要注意的是,alias指令会在URL中保留location部分的路径,如果想要去掉location部分的路径,可以使用root指令:

server {
    listen 80;
    server_name example.com;

    location /files {
        root /path/to/files/directory;
    }
}

这样,当访问http://example.com/files时,nginx会将请求映射到/path/to/files/directory目录下的文件,但URL中不会保留location部分的路径。

0
看了该问题的人还看了