Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 would return my_file

Here's my config so far

    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 would return my_file – titiyoyo Jun 2 '13 at 18:28
Why bother with a query string then? Just use an alias and try_files. – Michael Hampton Jun 2 '13 at 18:31

Your Answer


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

Browse other questions tagged or ask your own question.