我在 Ubuntu 14 中使用 apache2,并为多个域设置了多个 conf 文件。但是,当我尝试使用类似的 conf 文件添加新域时,它不起作用。新域的 conf 文件如下所示:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.rampatra.com
#ServerAlias www.rampatra.com
ServerAdmin [email protected]
DocumentRoot /var/www/rampatra.com
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.rampatra.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# WWW Redirect
<VirtualHost *:80>
ServerName rampatra.com
Redirect permanent / http://www.rampatra.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =rampatra.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
我遇到的问题是,当我访问 rampatra.com 时,它会将我重定向到另一个域,但是,我有完全相同的配置文件ramswaroop.me并且运行正常。你们能告诉我这里我遗漏了什么吗?
答案1
添加两个 conf 文件解决了这个问题。一个rampatra.com.conf
和另一个rampatra.com-le-ssl.conf
。我需要第二个 conf 文件,因为我正在使用 let's encrypt 的 ssl 证书。
另外,不要忘记通过以下方式启用该网站:
sudo a2ensite rampatra.com.conf
sudo a2ensite rampatra.com-le-ssl.conf
最后,通过以下方式重新启动 apache2 服务器:
sudo service apache2 restart