Pinax(13,“权限被拒绝”)
我是个菜鸟,但我使用 python manage.py runserver 让我的应用程序工作得很好,但是当我将它带到 Apache + mod_wsgi 时,我不断收到此错误。调试消息没有太大帮助。这是整个调试图像的屏幕截图: http://img694.imageshack.us/ img694/6723/screenshotfb.png
这是我的 http.conf 文件的转储。
WWSGIDaemonProcess cloud-tester python-path=/home/ubuntu/.virtualenvs/pinax-env/lib/python2.6/site-packages
WSGIProcessGroup cloud-tester
WSGIScriptAlias /cloudrunner /home/ubuntu/projects/cloudfly/deploy/pinax.wsgi
<Directory /home/ubuntu/projects/cloudfly/deploy>
Order deny,allow
Allow from all
</Directory>
pinax.wsgi 的内容是 Pinax 自带的。我没有改变任何东西。
我创建了一个示例“basic_project”,效果很好。这不。
提前致谢!对我应该做什么有什么建议吗?
I'm a noob but I made my application work beautifully using python manage.py runserver
but when I brought it to Apache + mod_wsgi, I keep getting this error. The debug messages aren't much help. Here is a screenshot of the entire debug image: http://img694.imageshack.us/img694/6723/screenshotfb.png
Here is the dump of my http.conf file.
WWSGIDaemonProcess cloud-tester python-path=/home/ubuntu/.virtualenvs/pinax-env/lib/python2.6/site-packages
WSGIProcessGroup cloud-tester
WSGIScriptAlias /cloudrunner /home/ubuntu/projects/cloudfly/deploy/pinax.wsgi
<Directory /home/ubuntu/projects/cloudfly/deploy>
Order deny,allow
Allow from all
</Directory>
The contents of pinax.wsgi is what comes with Pinax. I didn't change anything.
I created a sample "basic_project", and that works fine. This doesn't.
Thanks in advance! Any advice on what I should do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Apache/mod_wsgi 下,您的代码将以 Apache 用户身份运行,并且通常不具有写入您作为用户拥有的目录的访问权限。阅读:
http://code.google.com/p/modwsgi/wiki/ ApplicationIssues#Access_Rights_Of_Apache_User
最简单的方法是运行使守护进程以与手动运行代码相同的用户身份运行。为此,请使用 WSGIDaemonProcess 的“用户/组”选项。阅读:
http://code.google.com/p/modwsgi/wiki/ ConfigurationDirectives#WSGIDaemonProcess
另一个问题可能是您在代码中使用了相对路径名。这在 Apache 下不起作用,因为当前工作目录可以是任何目录。您确实应该始终使用绝对路径名,或者至少相对于正在执行的代码文件的 __file__ 的 os.path.dirname() 来计算它们。
如果您真的不想处理它,可以解决此问题,是使用 WSGIDaemonProcess 的 'home' 选项将守护进程的当前工作目录设置为手动运行服务器的同一目录。请参阅上面引用的 WSGIDaemonProcess 的相同文档。
Under Apache/mod_wsgi your code will run as Apache user and will not usually have access rights to write to directories that you as a user has. Read:
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User
The easiest way around that is run make the daemon process run as same user as you manually run the code. Use the 'user/group' options to WSGIDaemonProcess for this purpose. Read:
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
A further problem may be that you have used relative pathnames in your code. This will not work under Apache as the current working directory could be anything. You should really always use absolute path names, or at least calculate them relative to os.path.dirname() of __file__ for the code file it is being done in.
A way around this if you really don't want to deal with it, is to use the 'home' option to WSGIDaemonProcess to set current working directory of daemon process to same directory where you are running server by hand. See same documentation for WSGIDaemonProcess referenced above.
当您使用“python manage.py runserver”时,您将以root身份登录,这就是为什么它被允许写入该目录,但是当apache启动您的wsgi脚本时,它将在其用户名下,而不允许在您的目录中写入把你的Python脚本放进去。
假设你使用的是ubuntu服务器,我也遇到了同样的问题。我使用
chown www-data:www-data -R media
修复了它我将所有 py 脚本保存在 /var/pyproj/ 中。媒体文件夹位于 /var/pyproj//pysrc(my pinax installdirector)/site_media/
我将 wsgi 脚本、nginx conf 和 vhost.conf 保存在 /var/pyproj//server 中。
祝 Django 用户好运。我希望这有帮助。
You are logging in as root when you use 'python manage.py runserver' which is why it is allowed to write to that director but when apache launches your wsgi script it will be under its user name which isnt allowed to write in the directory you have your python scripts in.
Assuming you are using ubuntu server, i had the same issue. I fixed it using
chown www-data:www-data -R media
I keep all my py scripts in /var/pyproj/. The media folder would be in /var/pyproj//pysrc(my pinax install director)/site_media/
I keep my wsgi script, nginx conf and vhost.conf in /var/pyproj//server.
Best of luck fellow django user. I hope this helps.