niginx 配置多文件路径访问图片静态资源
要配置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/jfXn 著作权归作者所有。请勿转载和采集!