django - 使用 apache 和 mod_wsgi 时,我在哪里存储 django 项目代码?

标签 django apache mod-wsgi

我正在查看 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/

相关文章:

django - Django中的并发性能(apache2 prefork/mod_wsgi),我在做什么错?

python - 使用 Apache 和多个 Django 站点的奇怪、不一致的行为

django - 如何在django中实现拖放上传文件,而我已经实现了简单的文件上传

sql - 如何在没有 RawSQL 的情况下在 Django 中创建和访问正则表达式捕获组?

php - 从 PHP 运行 Perl 脚本以在服务器上创建新目录

php - 30 秒后出现 502 Bad gateway 错误

python - Apache + mod_wsgi - 来自同一浏览器的并行请求

django - 如何在 Django 中压缩压缩迁移?

python - 如何在 Django 模板中组合查询集和字典?

java - Tomcat集群