2011-01-31 21 views
1

好吧,所以我几乎有标准的nginx配置服务于一个独角兽导轨服务器(侦听套接字文件,并从rails_app/public目录中提供静态文件)。如何在服务独角兽导轨服务器时从nginx获得来自两个位置的静态文件?

不过,我要做到以下几点:

  1. 从 rails_app /公众提供静态文件(如目前 完成)
  2. 服务与不同的根URL /报告/静态文件(喜欢的/ mnt /文件/)

我尝试添加以下到我的nginx的配置:

location /reports/ { 
    root /mnt/matthew/web; 
} 

但它没有工作。

任何想法如何让这种情况发生?

(下面是我的整个nginx.conf文件:

worker_processes 1; 

pid /tmp/nginx.pid; 
error_log /tmp/nginx.error.log; 

events { 
    worker_connections 1024; # increase if you have lots of clients 
    accept_mutex off; # "on" if nginx worker_processes > 1 
    # use epoll; # enable for Linux 2.6+ 
    # use kqueue; # enable for FreeBSD, OSX 
} 

http { 
    # nginx will find this file in the config directory set at nginx build time 
    include mime.types; 

    # fallback in case we can't determine a type 
    default_type application/octet-stream; 

    # click tracking! 
    access_log /tmp/nginx.access.log combined; 
    sendfile on; 

    tcp_nopush on; # off may be better for *some* Comet/long-poll stuff 
    tcp_nodelay off; # on may be better for some Comet/long-poll stuff 
    gzip on; 
    gzip_http_version 1.0; 
    gzip_proxied any; 
    gzip_min_length 500; 
    gzip_disable "MSIE [1-6]\."; 
    gzip_types text/plain text/html text/xml text/css 
      text/comma-separated-values 
      text/javascript application/x-javascript 
      application/atom+xml; 

    # this can be any application server, not just Unicorn/Rainbows! 
    upstream app_server { 
    server unix:/home/matthew/server/tmp/unicorn.sock fail_timeout=0; 


    } 

    server { 
    # enable one of the following if you're on Linux or FreeBSD 
    listen 80 default deferred; # for Linux 
    # listen 80 default accept_filter=httpready; # for FreeBSD 


    client_max_body_size 4G; 
    server_name _; 

    keepalive_timeout 5; 

    location /reports/ { 
     root /mnt/matthew/web; 
    } 
    # path for static files 
    root /home/matthew/server/public; 



    try_files $uri/index.html $uri.txt $uri.html $uri @app; 

    location @app { 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 

     proxy_pass http://app_server; 
    } 

    # Rails error pages 
    error_page 500 502 503 504 /500.html; 
    location = /500.html { 
     root public; 
    } 
    } 
} 
+0

也许这是一个愚蠢的选择,但是如何从/ home/matthew/server/public/otherstuff到软链接/ mnt/files /以避免根变更问题? – 2014-06-04 03:38:31

回答

4

location @app是寻找/home/matthew/server/public文件,因为这是指定的父根如果尝试文件语句在location /reports/匹配的文件,有一个这些文件不会被找到你需要设置这样的东西:

location /reports/ { 
    root /mnt/matthew/web; 
    try_files $uri/index.html $uri.txt $uri.html $uri @foo; 
} 
root /home/matthew/server/public; 
try_files $uri/index.html $uri.txt $uri.html $uri @app; 

location @foo { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 

    proxy_pass http://app_server; 

    root /mnt/matthew/web 
} 

location @app { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 

    proxy_pass http://app_server; 
} 
相关问题