Finally able to directly serve static files with permission using nginx.
Thanks Michael for your suggestion.
Just want to share my approach below:


#location configuration in nginx.conf

        location ^~ /resources/  {
                internal;
                root /path/to/myapp;
            }

--------------------------------------
# __init__.py

    #add route for static files with permissions
    config.add_route('resource_file', '/MyFiles/{filename}')
    config.add_view(view='myapp.views.resource_file',
    route_name='resource_file',
    permission='special')

----------------------------------------------

# myapp.views

import os
from pyramid.response import Response

def resource_file(request):
_here = os.path.dirname(__file__)
file_name = request.matchdict['filename']
pdf_file = open(os.path.join(_here, 'resources',file_name)).read()
response = Response(content_type='application/pdf',
headers={'X-Accel-Redirect':'/resources/'+file_name},
body=pdf_file)
return response

On Sun, Oct 9, 2011 at 12:55 PM, Sharil Shafie <[email protected]> wrote:

> ops. The #internal was actually be uncommented. I commented it as temporary
> measure.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to