Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to setup a virtual location in nginx in order to serve large static files from a directory. The main app is a symfony2 program.

What I would like to do is having an url where you could specify a filepath within a GET parameter, that way nginx could serve the file directly to the client.

In my config the location would be /getfile An example call would be this : a request to http://myserver.com/getfile?file=path/to/my_file would return my_file

Here's my config so far

server
{
    listen                                              80;
    server_name                                         website_url;
    set                                                 $path_web /myapp/webdir;

    client_max_body_size                                200m;   

location /getfile {             
    root /path_to_dir;
        if ($args ~ ^oid=(.*+)) {
          set $key1 $1;
          rewrite ^.*$  $key1;
        }   
    }

location ~ \.php($|/)
{
      set  $script     $uri;
      set  $path_info  "";

      if ($uri ~ "^(.+\.php)(.*)") {
          set  $script     $1;
          set  $path_info  $2;
      }


      fastcgi_pass   unix:/tmp/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $path_web$script;
      fastcgi_param  SCRIPT_NAME      $script;
      fastcgi_param  PATH_INFO        $path_info;

      include   /etc/nginx/conf.d/fastcgi.conf;
}


    root                                                    $path_web;
    index                                                   app.php app_dev.php;

    location / 
    {   
    set $idx_file app.php;

    if ($args ~ debug=true) {
        set $idx_file app_dev.php;
        }

        if ( !-f $request_filename) {
    rewrite ^(.*)$ /$idx_file last; 
        }
    }

    location ~ /\.ht
    {
    deny                 all;
    }



    # logs path
    access_log                                          /path_to_logdir/access.log main;
    error_log                                           /path_to_logdir/error.log;
}
share|improve this question
    
What have you tried so far? Is there anything in that configuration that's relevant to your question? Have you never heard of try_files? –  Michael Hampton Jun 2 '13 at 18:00
    
well yes, as I said I'm trying to setup a location called /getfile which would serve static files from a directory. It's mentioned in my question. An example would be this : a request to myserver.com/getfile?file=path/to/my_file would return my_file –  titiyoyo Jun 2 '13 at 18:28
1  
Why bother with a query string then? Just use an alias and try_files. –  Michael Hampton Jun 2 '13 at 18:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.