safely hosting a django project over apache using centos

扶醉桌前 提交于 2019-12-25 04:15:48

问题


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.


回答1:


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.




回答2:


Well, under /home is not the right place, thanks to SELinux. Put the app under /srv instead.



来源:https://stackoverflow.com/questions/2894611/safely-hosting-a-django-project-over-apache-using-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!