Nginx 多文件路径访问图片静态资源配置教程
要配置 Nginx 以允许多个文件路径访问图片静态资源,您可以按照以下步骤进行操作:
-
打开 Nginx 配置文件。默认情况下,该文件位于
/etc/nginx/nginx.conf或/usr/local/nginx/conf/nginx.conf。 -
在
http块内添加一个新的server块,用于配置多个文件路径的访问。
http {
...
server {
listen 80;
server_name example.com;
location '/images/' {
root '/path/to/images1';
try_files $uri $uri/ =404;
}
location '/pictures/' {
root '/path/to/images2';
try_files $uri $uri/ =404;
}
}
...
}
在上面的配置中,我们创建了两个不同的 location 块,分别用于 /images/ 和 /pictures/ 路径。root 指令用于指定文件路径的根目录。
- 重启 Nginx 服务器以使配置生效。
sudo systemctl restart nginx
现在,您可以通过访问 http://example.com/images/ 和 http://example.com/pictures/ 来访问相应的图片静态资源。
原文地址: https://www.cveoy.top/t/topic/dodr 著作权归作者所有。请勿转载和采集!