如何在ubuntu上将文件夹添加到虚拟apache2主机?

时间:2017-02-13 09:17:45

标签: apache ubuntu

我已经使用关注

在ubuntu 16.04上创建了一个虚拟apache 2主机
        1) sudo mkdir -p /var/www/share.com/public_html
        2) sudo chown -R $USER:$USER /var/www/share.com/public_html
        3) sudo chmod -R 755 /var/www
        4) sudo nano /var/www/share.com/public_html/index.html
        5) inside index.html following is added
                    <html>
                    <head>
                    <title>WELCOME!!1</title>
                    </head>
                    </html>
        6) cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/share.com.conf
        7) sudo nano /etc/apache2/sites-available/share.com.conf
             inside share.com.conf
                       serverAdmin info@share.com
                       serverName share.com
                       Documentroot var/www/share.com/public_html
        8) sudo a2ensite share.com.conf
        9) sudo a2disite 000-default.conf
        10) sudo service apache2 restart
        11) sudo nano /etc/hosts
        inside host file
          127.0.0.1       ubuntu-controller       ubuntu-controller
            127.0.0.1       localhost
            127.0.1.1       vagrant
            192.168.10.10 share.com
            127.0.0.1 testsite.lk
            ::1     localhost ip6-localhost ip6-loopback
            ff02::1 ip6-allnodes
            ff02::2 ip6-allrouters

如果我输入192.168.10.10,在浏览器中执行上述操作后,我将页面显示为:

enter image description here

Actualy我应该在浏览器中看到index.html内容为&#34; WELCOME&#34;没有显示,如果我试图打开&#34; www.share.com&#34;没有显示出来。其次我想在主机内添加文件夹所以,请帮助我如何在服务器上添加文件夹。

1 个答案:

答案 0 :(得分:0)

  

如果我输入192.168.10.10,从浏览器执行上述操作后,我得到了   该页面为......

这是预期的行为,因为您输入的是IP而不是share.com。当请求进入服务器时,Apache会将传入HTTP请求的Host字段与ServerName匹配,因此IP地址将与share.com不匹配。

同样a2disite 000-default.conf,不会禁用默认目录。当没有任何匹配时,Apache使用它作为运行的地方。你会想要放置一些什么都不做的简单HTML文件,或者显示错误,而不是默认页面。

在您的Apache配置中,您有:

serverName share.com
Documentroot var/www/share.com/public_html

应该是:

ServerName share.com
DocumentRoot var/www/share.com/public_html
  

Actualy我应该在浏览器中看到index.html内容为   “WELCOME”,如果我尝试打开,则不会显示   “www.share.com”没有显示出来。

您需要输入share.com,因此它与ServerName匹配。

相关问题