VirtualHost配置不允许第二个网站运行

时间:2014-09-17 17:44:52

标签: django apache apache2 virtualhost wsgi

我在/etc/apache2/sites-available/staginnx.com.conf

中有这个
WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
WSGIPythonPath /home/ubuntu/v1/staginnx-info/app/website

<VirtualHost *:80>

        # Admin email, Server Name (domain name) and any aliases
        ServerAdmin info@staginnx.com
        ServerName  staginnx.com
        ServerAlias www.staginnx.com

        <Directory /home/ubuntu/v1/staginnx-info/app/website/website>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>

        Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/

        <Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
            Require all granted
        </Directory>

        Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico

        ErrorLog /var/log/apache2/error.log

</VirtualHost>

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin blog.staginnx@staginnx.com
  ServerName  blog.staginnx.com
  ServerAlias blog.staginnx.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php
  DocumentRoot /var/www/html/blog/

  <Directory /var/www/html/blog>
   Require all granted
  </Directory>

  # Custom log file locations
  LogLevel warn
  ErrorLog  /var/www/html/blog/log/error.log
  CustomLog /var/www/html/blog/log/access.log combined

</VirtualHost>

现在第一个,主网站工作正常。第二个, BLOG 无效。

我已完成sudo a2ensite staginnx.com.conf,并在sites-enabled生成符号链接。我已经完成了重载apache并重新启动。

四处游荡,但没有运气。

想在我的博客文件夹中安装wordpress博客。

1 个答案:

答案 0 :(得分:1)

要在虚拟主机中使用django应用程序,您需要在虚拟主机设置中设置WSGIScriptAlias,并且无法使用WSGIPythonPath,您需要使用WSGIDaemonProcess就像在以下设置中一样。

<VirtualHost *:80>
    WSGIScriptAlias / /home/ubuntu/v1/staginnx-info/app/website/website/wsgi.py
    WSGIDaemonProcess example.com python-path=/home/ubuntu/v1/staginnx-info/app/website

    # Admin email, Server Name (domain name) and any aliases
    ServerAdmin info@staginnx.com
    ServerName  staginnx.com
    ServerAlias www.staginnx.com

    <Directory /home/ubuntu/v1/staginnx-info/app/website/website>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static/ /home/ubuntu/v1/staginnx-info/app/website/ui/static/

    <Directory /home/ubuntu/v1/staginnx-info/app/website/ui/static>
        Require all granted
    </Directory>

    Alias /favicon.ico /home/ubuntu/v1/staginnx-info/app/website/ui/static/images/favicon.ico

    ErrorLog /var/log/apache2/error.log

</VirtualHost>

如果您想在同一主机上托管多个应用程序,那么您还需要更改wsgi.py文件中的小设置。

而不是使用

os.environ.setdefault(DJANGO_SETTINGS_MODULE, "app.settings")

你应该使用

os.environ["DJANGO_SETTINGS_MODULE"] = "app.settings"

我希望这会对你有所帮助。

For WSGIDaemonProcess setting