Django:Apache DocumentRoot不存在

时间:2012-05-25 14:57:41

标签: django apache document-root

我正在尝试使用mod_wsgi,CentOS 6在apache 2.6.6上运行Django 1.3.1。

我已经更改了httpd.conf文件:

WSGIPythonPath /var/www/vhosts/domain.co.uk
<VirtualHost *:80>
  #ServerName domain.co.uk
  ServerName 46...233

  ##DocumentRoot /var/www/vhosts/domain.co.uk/httpdocs

  LogLevel debug
  ErrorLog /var/www/vhosts/domain.co.uk/logs/error.log
  CustomLog /var/www/vhosts/domain.co.uk/logs/access.log combinedio

  HostnameLookups Off

  UseCanonicalName On

  WSGIScriptAlias / /var/www/vhosts/domain.co.uk/sites/somod/apache/django.wsgi
  WSGIDaemonProcess somod:80 user=somod group=psaserv processes=1 threads=1
  WSGIProcessGroup somod:80
  #WSGIPythonPath /var/www/vhosts/domain.co.uk

  Alias /robots.txt /var/www/vhosts/domain.co.uk/sites/templates/robots.txt
  Alias /favicon.ico /var/www/vhosts/domain.co.uk/sites/media/favicon.ico

  <Directory "/var/www/vhosts/domain.co.uk/httpdocs">
    AllowOverride None
    Options -ExecCGI -Includes -FollowSymLinks -Indexes
    Order allow,deny
    Allow from all
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
  </Directory>

  <Directory "/var/www/vhosts/domain.co.uk/sites">
    AllowOverride None
    Options +ExecCGI -Includes +FollowSymLinks -Indexes
    Order allow,deny
    Allow from all
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
  </Directory>

  Alias /media "/var/www/vhosts/domain.co.uk/media"
  <Location "/media/">
    SetHandler None
  </Location>
</VirtualHost>

所以我粘贴了我的apache配置(只添加了我的代码)。这是/etc/httpd/conf/httpd.conf

我现在可以重启apache而不会出现任何错误,但网站尚未显示。很遗憾,我无法运行sudo a2enmod wsgi,我正在使用cenos 6而a2enmod无效。但我确定它已经安装,因为我订购vps,只是不确定它是否正在运行。我会检查一下。

我现在的问题是网站应该是什么网址?它的值是ServerName还是ip address/ServerName value?我可以使用ip地址吗?因为我想在我切换域之前运行网站并确保一切正常,因为现在这个域名下面是我正在迁移到新服务器的网站。

非常感谢您的帮助

1 个答案:

答案 0 :(得分:3)

不知道你在做什么,但这里是你兄弟的示例配置:

WSGIPythonPath /var/www/yoursite
<VirtualHost *:80>
    ServerName yoursite.com
    ServerAlias testing.yoursite.com

    Alias /static/ /var/www/yoursite/yourdjangoproject/static/
    # Alias /sitemap.xml /var/www/yoursite/yourdjangoproject/static/sitemap.xml
    WSGIScriptAlias / /var/www/yoursite/yourdjangoproject/wsgi.py

    <Directory />
        AllowOverride None
        Options -Indexes
    </Directory>

    <Directory /var/www/yoursite/.git/>
        Deny From All 
    </Directory>

    LogLevel info
    ErrorLog /var/log/apache2/yoursite-error.log
    CustomLog /var/log/apache2/yoursite-access.log combined
</VirtualHost>

创建此文件并将其命名为yoursite并将其放在/etc/apache2/sites-available下。然后运行sudo a2ensite yoursite,它也将被取消sites-enabled

这取决于:

  • apache2
  • libapache2-mod-wsgi

通过运行sudo a2enmod wsgi确保启用wsgi。

我建议您在版本控制仓库中使用该文件,然后将其与/etc/apache2/sites-available进行符号链接。

另请注意,我为/ static /创建了一个别名,如果您想使用它,请确保运行sudo ./manage.py collectstatic。这会将所有静态文件放在/var/www/yoursite/yourproject/static

中 祝你好运。