Ubuntu安装Apache

安装

Ubuntu下安装Apache:

apt-get install apache2

安装成功后,网站默认的根目录是/var/www/html,该文件夹下现在有一个index.html文件。现在用浏览器访问公网IP是可以打开“
Apache2 Ubuntu Default Page ”页面的。

Apache的两个配置文件:

  • /etc/apache2/apache2.conf
  • /etc/apache2/sites-available/000-default.conf

修改网站根目录

比如,我想把/vw/作为网站根目录。

  • 修改/etc/apache2/apache2.conf:找到”Directory /var/www/”,把”/var/www/”改为新的根目录”/vw/”就可以了。

  • 修改/etc/apache2/sites-available/000-default.conf:找到”DocumentRoot /var/www/html”,把”/var/www/html”改为新的根目录”/vw”就可以了。

  • 重启 Apache:/etc/init.d/apache2 restart

  • 复制“index.html”文件到/vw目录下:cp /var/www/html/index.html /vw/

现在在浏览器中输入公网IP,可以访问。

为多个域名设置不同的网站根目录

假设现在有两个域名www.example1.com和www.example2.com,并且两个域名都解析到同一个IP,那么默认情况下用这两个域名访问的网站是同一个网站。

现在想让不同的域名访问不同的网站,这时就需要为两个域名设置不同的根目录。首先修改apache2.conf文件,找到一组:

<Directory>
</Directory>

在后面加上你的另一个网站的根目录,比如用/vw1:

<Directory /vw1>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

然后修改site-enabled/000-default.conf(应该修改site-available/000-default.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 /vw
        ########################################################
        ServerName www.example1.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
########################################################
<VirtualHost *:80>
        DocumentRoot /vw1
        ErrorLog ${APACHE_LOG_DIR}/victoriawy_error.log
        ServerName www.example2.com
</VirtualHost>
########################################################

修改后,重启服务器。

现在,用两个域名访问的就是两个不同的网站了。那么,还有一个问题:此时输入IP,会访问哪一个呢?目前,我的是访问第一个,但是我也不知道是什么决定的,先后顺序吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值