apache2 - 虚拟主机中的ServerName无法正常工作

时间:2014-06-04 03:07:57

标签: apache2 localhost virtualhost virtual-hosts server-name

这是我第一次在计算机中配置虚拟主机以进行本地工作和测试。我正在尝试访问我在site-available / default上配置的blog.dev,但它无法正常工作。这是我的网站 - 可用/默认:

<VirtualHost *:80>
    ServerAdmin eduguimara@gmail.com

    ServerName blog.dev
    ServerAlias www.blog.dev
    DocumentRoot /var/www/crud/public
    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    <Directory /var/www/crud/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride All
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

我做了sudo a2ensite blog.dev.conf和sudo service apache2 restart。 根据我找到的指南,帮助和教程,它应该运行。但是我的浏览器找不到http://blog.dev 当我键入localhost时,它仍然有效,但ServerName不起作用。 在ports.conf上可以使用NameVirtualHost *:80 我尝试在sites-available /目录中配置一个名为blog.dev.conf的新文件,但它仍无效。

2 个答案:

答案 0 :(得分:1)

您需要将以下条目放在/ etc / hosts文件中:

127.0.0.1    blog.dev

答案 1 :(得分:0)

如果blog.dev不是真正的域名,并且您没有指向服务器的DNS条目,那么您需要在系统的主机文件中添加虚假条目,以便域名名称可以解决。

在Windows下,您可以将条目添加到位于此处的hosts文件中: C:\ Windows \ System32下\驱动程序\等\主机

然后正如THEcreationist所说,在一行上添加127.0.0.1 blog.dev。

对于Linux环境,请参阅THEcreationist的回复。

通过它的声音可以解决你的问题。