Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
nginx从root提供静态文件,并从alias上传文件_Nginx - Fatal编程技术网

nginx从root提供静态文件,并从alias上传文件

nginx从root提供静态文件,并从alias上传文件,nginx,Nginx,我将nginx作为apache前面的反向代理服务器运行。 我需要在后端从前端访问上传的文件,所以方法是在nginx站点配置中使用别名,但是后端的静态文件应该由nginx直接处理。我是nginx新手,所以这里是我处理静态文件的部分配置。我还指定了一个别名(/images),但它不起作用,因为它被第二个条件覆盖。 如何将这两个条件结合起来,使nginx能够处理来自root(后端应用程序)的静态文件和来自前端应用程序的上传文件。 在apache配置中,我为这个问题提供了一个别名,它可以工作,但前面没有

我将nginx作为apache前面的反向代理服务器运行。 我需要在后端从前端访问上传的文件,所以方法是在nginx站点配置中使用别名,但是后端的静态文件应该由nginx直接处理。我是nginx新手,所以这里是我处理静态文件的部分配置。我还指定了一个别名(/images),但它不起作用,因为它被第二个条件覆盖。 如何将这两个条件结合起来,使nginx能够处理来自root(后端应用程序)的静态文件和来自前端应用程序的上传文件。 在apache配置中,我为这个问题提供了一个别名,它可以工作,但前面没有nginx

这是我的部分nginx配置:

  server {
       listen 80;

       root /var/www/website/backend/www;

       # Add index.php to the list if you are using PHP
       index index.html index.php index.htm;

       server_name admin.website.com www.admin.website.com;

       location / {
                proxy_pass http://localhost:8080;
                include /etc/nginx/proxy_params;
       }
#The alias to handle uploaded files(.jpeg, .pdf) from frontend
      location  /images {
               alias /var/www/website/frontend/www/images;
      }
#let nginx handle static files from root
       location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
               expires      30d;
       }
.
.
.
}

正则表达式
位置
块优先于前缀
位置
块(除非使用
^
修饰符
)。有关详细信息,请参阅

尝试:

请注意,在这种情况下,首选
root
指令(有关详细信息,请参阅)

location ^~ /images {
    root /var/www/website/frontend/www;
}