/etc/apache2/sites-available
我有一个名为的虚拟主机attrave.com.conf
以下是该虚拟主机文件的代码(仅附加相关代码):
ServerName attrave.com
ServerAdmin [email protected]
ServerAlias www.attrave.com
DocumentRoot /var/www/attrave.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/attrave.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
我希望能够www.attrave.com
仅通过即可访问该网站attrave.com
。
目前,当我浏览时,attrave.com
它会带我到/var/www/
目录,而它实际上应该带我到实际的attrave.com文件夹。当我包含www.
所有内容时,一切都正常,但这令人沮丧。
编辑:这是我更新的虚拟主机文件:(这仍然不起作用)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<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.attrave.com
ServerAdmin [email protected]
ServerAlias www.attrave.com
DocumentRoot /var/www/attrave.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/attrave.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
更新2:
我尝试了你提出的所有建议,但仍然无法让网站正常运行“attrave.com”. 它在“www.attrave.com”。
我附上了相关内容的文本,希望能够让大家对这个问题有更多的了解。
Attrave.com.conf(虚拟主机文件)
DocumentRoot /var/www/attrave.com ServerName attrave.com ServerAlias attrave.com www.attrave.com ServerAdmin [email protected] <Directory /var/www/attrave.com> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
/etc/hosts 文件
# Your system has configured 'manage_etc_hosts' as True. # As a result, if you wish for changes to this file to persist # then you will need to either # a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl # b.) change or remove the value of 'manage_etc_hosts' in # /etc/cloud/cloud.cfg or cloud-config from user-data 127.0.0.1 localhost
Apache2.conf 文件
<Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #<Directory /srv/> # Options Indexes FollowSymLinks # AllowOverride None # Require all granted #</Directory>
答案1
你尝试过吗:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/attrave.com
Servername attrave.com
# Other directives here
</VirtualHost>