我正在使用Python,Flask和Apache,而且我被卡住了。 当我尝试访问使用www的mywebsite,它工作正常。 然而,当我删除www,该网站正在显示“索引/”下一个空的文件列表。 我读过所有可能的解决scheme,在我的情况下没有任何作用。 我正在使用WSGI,这意味着DocumentRoot是不相关的,因为我使用WSGIScriptAliasvariables。 按照指示使用ServerAlias – 不起作用。 我已经在我的DNS选项中设置了2个独立的Alogging,都指向相同的IP。 当我用www平网站,没有它,相同的IP地址显示
<VirtualHost *:80> ServerName mysite.com ServerAlias www.mysite.com WSGIScriptAlias / /var/www/mysite/mysite.wsgi <Directory /var/www/mysite/mysite/> Order allow,deny Allow from all </Directory> Alias /static /var/www/mysite/mysite/app/static <Directory /var/www/mysite/mysite/app/static/> Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined ... </VirtualHost>
有任何想法吗?
这是“apachectl -S”命令的输出:
VirtualHost configuration: *:80 is a NameVirtualHost default server mysite.com (/etc/apache2/sites-enabled /000-default.conf:1) port 80 namevhost mysite.com (/etc/apache2/sites-enabled /000-default.conf:1) port 80 namevhost mysite.com (/etc/apache2/sites-enabled /mysite.conf:1) alias www.mysite.com ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www" Main ErrorLog: "/var/log/apache2/error.log" Mutex watchdog-callback: using_defaults Mutex default: dir="/var/lock/apache2" mechanism=fcntl PidFile: "/var/run/apache2/apache2.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="www-data" id=33 Group: name="www-data" id=33
看起来像/etc/apache2/sites-enabled/000-default.conf首先匹配您的请求。 远程此文件,它可能会有所帮助。
更新
是否保留默认的虚拟主机取决于你和你想要的。 如果您需要与您托pipe的域名完全匹配,默认的虚拟主机将pipe理所有到您服务器的请求,而不属于任何域。 这样的请求的例子可以是,如果你只是把服务器的IP到浏览器。
但是有些情况下,可以禁用默认的虚拟主机。 例如:您拥有多个域,全部使用相同的文档根目录。 而你想添加/删除域名没有Apache重新configuration。
为了理解虚拟主机匹配过程,我build议阅读以下文档: https ://httpd.apache.org/docs/2.4/vhosts/details.html