【问题标题】:Apache Virtual Host LocalhostApache 虚拟主机本地主机
【发布时间】: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


【解决方案1】:

我在 Windows 上运行它。所以在教程DigitalOcean 中,第 6 步对我不起作用(第 6 步 - 设置本地主机文件(可选))。我要做的是打开开始菜单,搜索“记事本”,右键单击,“以管理员身份打开”,打开文件,转到 C:\Windows\System32\drivers\etc\hosts 并在此处添加 example.com。一旦我这样做了,我就会被重定向到我的本地主机。谢谢@PrathameshPalav 的帮助!

【讨论】:

    猜你喜欢
    • 2011-05-13
    • 2015-09-14
    • 2011-06-19
    • 1970-01-01
    • 2018-11-27
    • 2019-08-25
    • 2012-04-26
    • 2012-09-25
    • 2011-03-25
    相关资源
    最近更新 更多