我正在查看 django 网站上似乎存在冲突的信息。
在此页面上: https://docs.djangoproject.com/en/1.7/intro/tutorial01/
它说:
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.
但是,在此页面上: https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/ 它说 Apache 应该这样设置:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
后者不是显示www根目录下的项目文件吗?
那么哪个是正确的呢?前者还是后者?
我使用了这些 linux 命令来设置项目:
cd /home/personal/network/django
django-admin.py startproject djnet
然后我将其放入 httpd.conf 中:
WSGIScriptAlias / /home/personal/network/django/djnet/wsgi.py
WSGIPythonPath /home/personal/network/django
<Directory /home/personal/network/django/djnet>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
这可行,但我担心我引用的第一页中的“这不利于安全”行。
我是否应该将 django-admin startproject
生成的项目代码放在与 Apache 目录分开的目录中?如果是这样,我将如何配置 Apache?
最佳答案
不是,为什么说它显示的是文档根目录下的文件呢?事实并非如此,它在“/path/to/mysite.com”中显示它们。您所做的事情是正确的,并且也不在网络根目录中。
关于django - 使用 apache 和 mod_wsgi 时,我在哪里存储 django 项目代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27924160/