【发布时间】:2018-06-26 16:31:55
【问题描述】:
您好,我的问题是当我尝试访问本地站点的 url 时,我没有得到正确的引导。这是我的设置:
/var/www/example.com有全部代码
/etc/apache2/sites-avaliable/example.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.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName example.com
ServerAlias www.example.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
<Directory "/var/www/html">
AllowOverride All
</Directory>
最后是我的 /etc/hosts
# This file is automatically generated by WSL based on the Windows hosts
file:
# %WINDIR%\System32\drivers\etc\hosts. Modifications to this file will be
overwritten.
127.0.0.1 localhost
127.0.0.1 example.com
当我 ping example.com 时,我得到了
PING example.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=128 time=0.392 ms
但是当我转到http://example.com 时,它只是普通的域站点。我清除了 Chrome 上的缓存,然后我
sudo service nscd restart
任何帮助将不胜感激,谢谢。
【问题讨论】:
-
“它只是普通的域名站点”是什么意思?
-
您将 DocumentRoot 指定为 html 文件夹,它应该是 www 内的 example.com
-
@PrathameshPalav 我没有被重定向,就好像我要去example.com一样。我更改了 documentroot,但是当我仍然访问 example.com 时,它不是我的本地主机
-
您可以按照此链接digitalocean.com/community/tutorials/…中的步骤进行操作
标签: apache web localhost virtualhost