Created
October 12, 2011 02:05
-
-
Save lxneng/1280031 to your computer and use it in GitHub Desktop.
Serving Static File with Permissions using Nginx, Uwsgi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment