我正在试图弄清楚如何从我的虚拟机托管第二个Django网站,我想知道是否有人能看到我犯了明显错误的地方。
目前设置为<VirtualHost *:80>
的网站无效。我从this answer了解到我应该将第二个网站指定为<VirtualHost *:8080>
。但是,当我尝试使用Listen
时,当我尝试重新加载apache
apache2.service的作业失败。请参阅'systemctl status apache2.service' 和'journalctl -xn'了解详情。
有没有人明白可能出现的问题?
为什么<VirtualHost *:80>
而非<VirtualHost *:8080>
?
为什么在指定Listen
时出现错误?
我正在使用Debian 8.5,Apache 2.4.10和mod-wsgi 4.3.0-1。
Listen 80
<VirtualHost *:80>
ServerName myserver.scss.tcd.ie/bias_experiment/
Alias /bias_experiment/static/ /var/www/bias_experiment/static/
<Directory /var/www/bias_experiment/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi
<Directory /var/www/bias_experiment/src/bias_experiment>
<Files index.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
ServerName myserver.scss.tcd.ie/bias_experiment_two/
Alias /bias_experiment_two/static/ /var/www/bias_experiment_two/static/
<Directory /var/www/bias_experiment_two/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /bias_experiment_two /var/www/bias_experiment_two/src/bias_experiment/index.wsgi
<Directory /var/www/bias_experiment_two/src/bias_experiment>
<Files index.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
任何帮助都是一如既往,非常感谢。
答案 0 :(得分:2)
您无法按原样设置ServerName
。 ServerName
指令必须是主机名,否则当您有多个VirtualHost
定义时,基于命名的虚拟主机将不起作用。完全处理任何事情的唯一原因是因为当基于名称的虚拟主机未正确设置或没有主机名匹配时,Apache会将请求发送到读取配置时找到的第一个VirtualHost
。如果您希望通过相同的主机名访问它们,那么您应该做的就是将所有内容放在一个VirtualHost
中。可以使用不同的端口,但不太方便。
<VirtualHost *:80>
ServerName myserver.scss.tcd.ie
WSGIDaemonProcess bias_experiment
Alias /bias_experiment/static/ /var/www/bias_experiment/static/
<Directory /var/www/bias_experiment/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi \
process-group=bias_experiment application-group=%{GLOBAL}
<Directory /var/www/bias_experiment/src/bias_experiment>
<Files index.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess bias_experiment_two
Alias /bias_experiment_two/static/ /var/www/bias_experiment_two/static/
<Directory /var/www/bias_experiment_two/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /bias_experiment_two /var/www/bias_experiment_two/src/bias_experiment/index.wsgi \
process-group=bias_experiment_two application-group=%{GLOBAL}
<Directory /var/www/bias_experiment_two/src/bias_experiment>
<Files index.wsgi>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
为了使WSGI应用程序保持独立,声明了两个单独的守护进程组,并将每个WSGI应用程序委派给另一个进程组。
然后将以下列方式访问两个WSGI应用程序:
如果这些是Django站点,您可能需要在Django设置文件中进行其他设置更改,以允许两者在相同的主机名下运行而不会相互干扰。