【发布时间】:2020-12-01 15:52:49
【问题描述】:
过去一天我一直被这个问题困扰,我尝试修复它的任何尝试都失败了。
我正在尝试将我的站点从 Windows IIS 迁移到 Ubuntu LAMP。我已经在 var/www/ 目录中设置了它们并为它们制作了配置文件。
我设置了 2 个虚拟主机:1 个用于 samtownsendmusic.co.uk,1 个用于www.swim-4u.co.uk (我认为只使用真实域而不是示例域可能更容易。)
这些是配置文件:
<VirtualHost samtownsendmusic.co.uk: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 samtownsendmusic.co.uk
ServerAlias samtownsendmusic.co.uk
ServerAdmin admin@samtownsendmusic.co.uk
DocumentRoot /var/www/samtownsendmusic.co.uk
RewriteEngine on
# 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} =samtownsendmusic.co.uk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
swim-4u.co.uk.conf
<VirtualHost www.swim-4u.co.uk: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.swim-4u.co.uk
ServerAdmin admin@swim-4u.co.uk
DocumentRoot /var/www/swim-4u.co.uk/
RewriteEngine on
# 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.swim-4u.co.uk
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
然后我去 samtownsendmusic.co.uk,它加载正常。 当我尝试访问 www.swim-4u.co.uk 时,它只会加载 samtownsendmusic.co.uk
我对 apache 和 linux 还很陌生,因此我们将不胜感激。谢谢
【问题讨论】:
-
显然要问,你重启apache了吗?试试
apachectl -S或httpd -S看看是否加载了vhost。 VirtualHost 块是否在同一个 conf 文件中? -
感谢您的回复。我确实重新加载并重新启动了apache。 httpd -S 命令显示“httpd:找不到命令”。虚拟主机 .confs 位于 /etc/apache2/sites-available/[site-name].conf 中自己的单独文件中
标签: apache ubuntu virtualhost lamp