安全托管在使用Apache的CentOS一个Django项目 [英] safely hosting a django project over apache using centos
问题描述
错误可以被看作/ p>
我有一个项目工作的伟大,但我在/ var / WWW的所有文件/和我有限的了解它的坏,根据Django的网站:
如果你的背景是在PHP中,你可能习惯于将code中的Web服务器的文档根目录下(在一个地方,如在/ var / WWW)。使用Django,你不这样做。这不是一个好主意,把任何这条巨蟒code的Web服务器的根文档,因为它的风险的可能性,人们或许可以通过网络来查看code,这是不利于安全。
把你的code在文档根目录的部分的之外,例如/ home /我的code。
所以我去了 /家庭/ TIPU /材料/
并执行 django-admin.py startproject命令twingle
。然后我去了Apache和做
<虚拟主机*:8080>
服务器名tweet_search_engine
的DocumentRoot /家庭/ TIPU /材料/ twingle /
< /虚拟主机><目录为/ home / TIPU /材料/ twingle>
SetHandler蟒蛇程序
PythonHandler django.core.handlers.modpython
SETENV DJANGO_SETTINGS_MODULE设置
PythonOption django.root /家庭/ TIPU /材料/ twingle
PythonDebug在
PYTHONPATH['/家庭/ TIPU /材料/','/家庭/ TIPU /材料/ twingle /'] + sys.path的
< /目录>
现在我得到一个403 Forbidden错误..任何知道我做错了吗?我更新到Linux(CentOS的)和Django的,所以我可以俯瞰一些很简单的事情。
这是几乎可以肯定只是一个访问权限问题。 Apache用户需要权限访问路径中的所有目录到你的项目 - 家庭,家庭/ TIPU,家庭/ TIPU /东东,家庭/ TIPU /材料/ twingle,等等。你需要找出用户的Apache作为运行,并授予读取权限的目录。
由于伊格纳西奥表明,/ SRV可能是一个更好的地方,把这个 - 但同样的权利问题仍然适用
Error can be seen at: http://djaffry.selfip.com:8080/
I had a project working great, but I had all the files under /var/www/ and with my limited understanding it's bad, according to django's site:
"If your background is in PHP, you’re probably used to putting code under the Web server’s document root (in a place such as /var/www). With Django, you don’t do that. It’s not a good idea to put any of this Python code within your Web server’s document root, because it risks the possibility that people may be able to view your code over the Web. That’s not good for security.
Put your code in some directory outside of the document root, such as /home/mycode."
So I went to /home/tipu/stuff/
and executed django-admin.py startproject twingle
. Then I went to apache and did
<VirtualHost *:8080>
ServerName tweet_search_engine
DocumentRoot /home/tipu/stuff/twingle/
</VirtualHost>
<Directory /home/tipu/stuff/twingle>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonOption django.root /home/tipu/stuff/twingle
PythonDebug On
PythonPath "['/home/tipu/stuff/', '/home/tipu/stuff/twingle/'] + sys.path"
</Directory>
Now I am getting a 403 Forbidden error.. any idea what I'm doing wrong? I'm newer to Linux (CentOS) and django, so I could be over looking some very simple things.
This is almost certainly just an access rights issue. The Apache user needs rights to access all the directories in the path to your project - home, home/tipu, home/tipu/stuff, home/tipu/stuff/twingle, and so on. You'll need to find out what user Apache is running as, and grant read rights to those directories.
As Ignacio suggests, /srv is probably a better place to put this - but the same rights issues still apply.
这篇关于安全托管在使用Apache的CentOS一个Django项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!