Anyway, below are the codes. Feel free to take and modify it if you think it
can be include in the cookbook. By the way, I put status code as 200. It can
be changed anyway. As has been put just now, provide the header of
X-Accel-Redirect
header containing the static file location,  nginx will take over to serve
the static file. It was the ignorance of me to put the body before.  TQ.

#file are located in /resources
#eg to open /resources/sample.pdf ->
http://www.mysite.com/MyFiles/sample.pdf

#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__)
filename = request.matchdict['filename']
response= Response(content_type='application/pdf',
headers={'X-Accel-Redirect':'/resources/'+filename})
response.status='200 OK'
return response

-- 
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