I use your nginx-drupal conf on github and follow your thread on g.d.o and nginx mailing list. Thank you for doing this module. I am planning to update most of my sites to d7 by the mid of this year. Will a d7 version of this module come out by then?

Comments

spacereactor’s picture

subscribing

perusio’s picture

Thanks for your interest in the module. I hope to have more time for getting the module up to speed on D7 later in the month. Right now I'm commited heavily to a lot of stuff, namely DrupalCamp Lisbon 2011.

I'm planning to work on other Nginx integration modules, addressing caching and security issues.

mike503’s picture

Version: » 6.x-1.x-dev

So nice to see an official module, I had hacked up xsend myself for this at one point.

I think D7 will add complexity since the file system stuff has been totally rewritten using the stream style paths.

+1 subscribing too

obrienmd’s picture

Really looking forward to a D7 port!

mattman’s picture

Status: Active » Needs review

Hey folks, No need to wait for a D7 port. I did an initial pass today!

Perusio, you'll find that I cloned your d.o. repo and pushed it up to my github account. The 7.x port is within a 7.x-1.x branch. Here's the link.

https://github.com/petrowsky/nginx_accel_redirect/tree/7.x-1.x

If you find the port to be good enough, you can merge the branch or you can make me a co-maintainer. I have d.o. git access and I'll be using the module in conjunction with one of my other modules on omega's boxes.

Enjoy!

perusio’s picture

Hello Matt,

Thanks for starting this much belated 7.x branch. I just pushed a new release of the 6.x branch that checks if the private files dir is protected and suggests the relevant Nginx configurations stanzas.

I'm going to look into it now. I'll be back :)

spacereactor’s picture

#5 i download your 7.x-1.x change the nginx_accel_redirect.info
version = 6.x-1.0
core = 6.x
to
version = 7.x-1.0
core = 7.x

There is my testing for drupal 7 and nginx_accel_redirect.

I set my Private file system path is outside of my website root
my website root is /var/www/mydomain.com/public_html
and my Private file system path is /var/www/mydomain.com/private/default

I upload the some image as private upload. Using Files transfered by PHP work but if switch to Files transferred by Nginx using X-Accel-Redirect. Flash my caches. Those private image doesn't display. If i switch back to Files transfered by PHP, image display again. I did not try to move my Private file system path within the website root
cause i intend to set my Private file system path outside the website root.

These are other modules i install with fresh drupal 7.2
- OG
- Ctools
- Views
- Entity api
- Transliteration

spacereactor’s picture

I finally get it work with #5 on drupal 7.2 and nginx 1.0.4

Because my private path is outside the webroot so i have change some part to get it to work. I think if your private path is within your drupal it should work. But for like me this is what is do. 3 things, edit nginx_accel_redirect.info so it can install into drupal 7, edit nginx_accel_redirect.module to point to "protected" folder, edit nginx domainname setting
==========================================
Edit nginx_accel_redirect.info
version = 6.x-1.0
core = 6.x
to
version = 7.x-1.0
core = 7.x

Edit nginx_accel_redirect.module
drupal_send_headers();
      // Setting the X-Accel-Redirect header for Nginx.
      header('X-Accel-Redirect: ' . base_path() . variable_get('file_private_path', ''). '/' . file_uri_target($uri));
      exit();
    }
to
drupal_send_headers();
      // Setting the X-Accel-Redirect header for Nginx.
      header('X-Accel-Redirect: /protected/'. '/' . file_uri_target($uri));
      exit();
    }

The last thing to do is edit your mydomain.com.conf
location ^~ /protected/ {
internal;
alias /var/www/mydomain.com/private/;
}
==========================================
My private path is /var/www/mydomain/private/ so change according to where you set your private path in drupal setting

All credit go to brianmercer, i look at http://groups.drupal.org/node/36892 for tips.

perusio’s picture

There's no need to hack anything. The module works with any path that is writable by the web server.

I created the 7.x-1.x-dev tag. Later today I'll update the module to bring it up to speed with the 6.x-1.x branch, namely verifying that the private files dir is protected.

perusio’s picture

Hello again Matt,

I've just commited the 7.x-1.x-dev version. I've given you commit access to the project. Thanks for your work on the D7 port and welcome aboard.

spacereactor’s picture

i use the 7.x-1.x-dev and i can't access to private files and images.

My website root is point at => /var/www/mydomain.com/public_html
My drupal is store at => /var/www/mydomain.com/public_html
My Private file system path is not within the webroot access.

Step taken on drupal.
1.) goto admin/config/media/file-system
- Public file system path => sites/default/files
- Private file system path => /var/www/mydomain.com/private/default
- Default download method => Private local files served by Drupal.
2.) install Nginx Accel Redirect and enable it.
3.) goto admin/config/media/file-system/nginx-accel-redirect
- X-Accel-Redirect: fast private file transfer support for Nginx => Files transferred by Nginx using X-Accel-Redirect
4.) check all files and image, all can't be view and download.

If i goto admin/config/media/file-system/nginx-accel-redirect and change it back to Files transfered by PHP then all files and images work.

lpalgarvio’s picture

+1 ;)

perusio’s picture

It's a very bad idea to specify full paths in the drupal filesystem settings form. That should be solely a prerrogative of the web server. Drupal shouldn't care about where the files are in the filesystem. Everything should be relative to its root.

Now to your problem. I fail to see any advantage of having the private files dir outside of your drupal root. Like I said in the discussion on the nginx g.d.o group if it's writable by the webserver, then it's accessible. You have always to protect it explicitly.

It's not even security by obscurity. Nevertheless, if you want to use it, do this:

1. Make a symlink from the drupal root to the directory where you want to have the private files.
ln -s ../private/default private on your drupal root.

2. On the settings form at admin/config/media/file-system enter just private.

3. Add the following to your vhost config:

     location ~ /private/ {
         internal;
      }
      

4. Reload your Nginx config service nginx reload.

5. Done.

I'm going to add this to the documentation.

spacereactor’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

I change Private file system path => sites/default/files/private
create new node with upload some file/image to private path. The node is block if access by http://mydomain.com/system/files/upload/project/photo/sample.jpg

But is access the file directly is accessible and downloadable when i access by http://mydomain.com/sites/default/files/private/upload/photo/sample.jpg

I using most or not all of the nginx drupal 7 setting with your https://github.com/perusio/drupal-with-nginx

perusio’s picture

It's because you must update your nginx config to protect the new location.

location ~* /private/ {
   internal;
}

This will work with any directory named private, no matter where it is located in the filesystem.

You can be more specific. In your case:

location ~* /sites/default/files/private/ {
   internal;
}

Depending on the remainder of your Nginx config you might try a literal location like:

location ^~ /sites/default/files/private/ {
   internal;
}
perusio’s picture

Assigned: Unassigned » perusio
Status: Needs review » Fixed

I just pushed the 7.x-1.0 release. Thanks to everyone that contributed. Specially Matt that got the 7.x ball rolling.

Test it and provide feedback.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.