1

我正在尝试使用 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地址吗?因为我想在切换域之前运行网站并确保一切正常,因为现在在这个域下是我正在移动到新服务器的网站。

非常感谢您的帮助

4

1 回答 1

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,它也会被放置 un sites-enabled

这取决于:

  • apache2
  • libapache2-mod-wsgi

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

我建议将文件放在版本控制存储库中,然后从/etc/apache2/sites-available.

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

祝你好运。

于 2012-05-25T20:27:53.610 回答