要配置 Nginx 以允许多个文件路径访问图片静态资源,您可以按照以下步骤进行操作:

  1. 打开 Nginx 配置文件。默认情况下,该文件位于 /etc/nginx/nginx.conf/usr/local/nginx/conf/nginx.conf

  2. 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 指令用于指定文件路径的根目录。

  1. 重启 Nginx 服务器以使配置生效。
sudo systemctl restart nginx

现在,您可以通过访问 http://example.com/images/http://example.com/pictures/ 来访问相应的图片静态资源。


原文地址: https://www.cveoy.top/t/topic/dodr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录