nginx重定向到外部文件夹

时间:2013-11-14 19:44:08

标签: nginx

这是我的nginx vhost conf:

upstream demo {
    server 127.0.0.1:9002 max_fails=250 fail_timeout=180s;
}

server {

    listen 80;
    server_name _;

    root /home/web/public;

    location /demo/ {
        proxy_pass http://demo/;
    }

    location /demo/assets/ {
        #this is where I need to point localhost/demo/assets (and all of it's subfolders) to another folder
        #the line below obviously doesn't work
        root /home/user/Workspaces/demo/public;
    }

}

根文件夹指向/home/web/public,但我需要网址localhost/demo/assets/及其所有子文件夹转到另一个(外部)文件夹。我该怎么做?

我正在运行nginx 1.4.3

1 个答案:

答案 0 :(得分:1)

您应该使用alias指令,并阅读the docs。只是引用它:

  

只需在 root 指令的值中添加URI即可构建文件的路径。如果必须修改URI,则应使用别名指令。

示例:

location /demo/assets/ {
    alias /home/user/Workspaces/demo/public/;
}