Django+;mod_wsgi:有人能就我的设置和重写规则向我提供建议吗

Django+;mod_wsgi:有人能就我的设置和重写规则向我提供建议吗,django,apache,apache2,mod-wsgi,linode,Django,Apache,Apache2,Mod Wsgi,Linode,这是我第一次将Django部署到最近收购的Linode服务器上,我很好奇是否有人可以检查我的部署,帮助我解决一些棘手的问题,并建议我是否做得不对 目录结构 Django的部署结构如何 不正确的URL命名 我在我的域名“example.com”上托管了名为“myapp”的Django应用程序。按照Django网站上的说明,我已经创建了它,因此应用程序的url.py必须以“/myapp”开头。这导致应用程序的域变为“example.com/myapp” 我如何设置它,使example.com只是我编

这是我第一次将Django部署到最近收购的Linode服务器上,我很好奇是否有人可以检查我的部署,帮助我解决一些棘手的问题,并建议我是否做得不对

目录结构 Django的部署结构如何

不正确的URL命名 我在我的域名“example.com”上托管了名为“myapp”的Django应用程序。按照Django网站上的说明,我已经创建了它,因此应用程序的url.py必须以“/myapp”开头。这导致应用程序的域变为“example.com/myapp”

我如何设置它,使example.com只是我编写的Django应用程序? 我只想导航到example.com,它会加载我的应用程序,而不是example.com/myapp

更奇怪的是,我本以为example.com会加载我的index.html文件,但它却试图找到Django的URL映射

Django日志文件写入权限 每当我将SSH连接到我的机器上的'syncdb'或'collectstatic',日志模块就会创建我在settings.py文件中命名的日志文件。这会给我带来问题,因为我是文件的所有者,apache2(www数据)无法写入。在我重新启动apache服务器之前,每次执行命令后都必须手动删除日志文件,这真让人恼火

这是我的/etc/apache2/sites available/example.com文件:

# domain: example.com
# public: /home/setheron/public/example.com/

WSGIPythonPath /home/setheron/public/example.com/applications/mysite:/home/setheron/env/lib/python2.7/site-packages

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin setheron@setheron.com
  ServerName  www.example.example.com
  ServerAlias example.com

  WSGIScriptAlias / /home/setheron/public/example.com/applications/mysite/mysite/wsgi.py

  Alias /static/ /home/setheron/public/example.com/applications/mysite/static/
  <Directory /home/setheron/public/example.com/applications/mysite/static/>
        Order deny,allow
        Allow from all
  </Directory>

  <Directory /home/setheron/public/example.com/applications/mysite/mysite>
  <Files wsgi.py>
        Order deny,allow
        Allow from all
  </Files>
  </Directory>

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/setheron/public/example.com/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/setheron/public/example.com/log/error.log
  CustomLog /home/setheron/public/example.com/log/access.log combined
</VirtualHost>
#域:example.com
#public:/home/setheron/public/example.com/
WSGIPythonPath/home/setheron/public/example.com/applications/mysite:/home/setheron/env/lib/python2.7/site-packages
#管理员电子邮件、服务器名(域名)和任何别名
服务器管理员setheron@setheron.com
服务器名www.example.example.com
ServerAlias example.com
WSGIScriptAlias//home/setheron/public/example.com/applications/mysite/mysite/wsgi.py
别名/static//home/setheron/public/example.com/applications/mysite/static/
命令拒绝,允许
通融
命令拒绝,允许
通融
#索引文件和文档根目录(公共文件所在的位置)
DirectoryIndex.html index.php
DocumentRoot/home/setheron/public/example.com/public
#日志文件位置
日志级别警告
ErrorLog/home/setheron/public/example.com/log/error.log
CustomLog/home/setheron/public/example.com/log/access.log组合

如果你想让Django为整个网站提供服务,那就去掉你的公共目录、索引等等。除了/static,您应该只需要WSGIScriptAlias指令。修正url.py,使其表示您的站点应该来自/而不是/myapp。

嘿,谢谢!我修好了。还有一个问题。是否必须为文件的www数据(apache)组设置权限?我想使用fabric,但我对文件权限设置感到困惑。@Setheron程序文件必须能被Web服务器进程读取才能运行。目录应该是可写的,以便生成.pyc文件。显然,日志文件应该是可写的。那么部署脚本将chgrp添加到包含所有文件/目录的apache组是典型的吗?我不会说“典型”,但这并不少见。
# domain: example.com
# public: /home/setheron/public/example.com/

WSGIPythonPath /home/setheron/public/example.com/applications/mysite:/home/setheron/env/lib/python2.7/site-packages

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin setheron@setheron.com
  ServerName  www.example.example.com
  ServerAlias example.com

  WSGIScriptAlias / /home/setheron/public/example.com/applications/mysite/mysite/wsgi.py

  Alias /static/ /home/setheron/public/example.com/applications/mysite/static/
  <Directory /home/setheron/public/example.com/applications/mysite/static/>
        Order deny,allow
        Allow from all
  </Directory>

  <Directory /home/setheron/public/example.com/applications/mysite/mysite>
  <Files wsgi.py>
        Order deny,allow
        Allow from all
  </Files>
  </Directory>

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/setheron/public/example.com/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/setheron/public/example.com/log/error.log
  CustomLog /home/setheron/public/example.com/log/access.log combined
</VirtualHost>