[英]Apache Virtual Host Localhost
Hi my problem is when I try to access my localsite's url, I do not get directed properly. 嗨,我的问题是,当我尝试访问本地站点的URL时,无法正确定向。 Here is my setup:
这是我的设置:
/var/www/example.com
has all the code /var/www/example.com
具有所有代码
/etc/apache2/sites-avaliable/example.conf /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>
and finally my /etc/hosts 最后是我的/ 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
When I ping example.com I get 当我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
But when I go to http://example.com it is just the normal domain site. 但是当我访问http://example.com时,它只是普通的域站点。 I cleared cache on Chrome and I
我清除了Chrome上的缓存,
sudo service nscd restart
Any help would be appreciated, thank you. 任何帮助,将不胜感激,谢谢。
I am running this on Windows. 我正在Windows上运行它。 So in the tutorial DigitalOcean , Step 6 did not work for me (Step Six — Set Up Local Hosts File (Optional)).
因此,在DigitalOcean教程中,步骤6对我不起作用(步骤6-设置本地主机文件(可选))。 What I had to do was open Start Menu, search 'Notepad', right click, 'open as admin', open file, go to C:\\Windows\\System32\\drivers\\etc\\hosts and add example.com here.
我要做的是打开“开始”菜单,搜索“记事本”,右键单击,“以管理员身份打开”,打开文件,转到C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts并在此处添加example.com。 Once I do that I get redirected to my localhost.
一旦这样做,我将被重定向到我的本地主机。 Thank you, @PrathameshPalav for the help!
谢谢@PrathameshPalav的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.