Ubuntu Apache2 安装及配置文件学习(及二级域名配置)

Apache2 安装:

  1. Install Apache.
    • apt install
      sudo apt-get install apache2
    • download and install
      $ sudo wget http://mirror.cc.columbia.edu/pub/software/apache//httpd/httpd-2.4.12.tar.gz
      $tar zxvf httpd-2.4.12.tar.gz
      $ ./configure [OPTION]... [VAR=VALUE]
      #such as ./configure --with-prefix=/usr/local/apache2 --with-apr= ......
      $ sudo make
      $ sudo make install.
  2. Enable apache.
    sudo /etc/init.d/apache2 start
  3. Check result:
    launch browser –> localhost –> It works!

配置文件解析:

就像main()函数一样,apache2 配置文件的加载也是有这样一个“main()”。 就是apache2_path/apache2.conf (主配置文件)
其他配置文件都是通过 include方式加载进来。 不建议修改此文件。

$ cat /etc/apache2/apache2.conf | grep Include
# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf
# Include all the user configurations:
Include httpd.conf
# Include ports listing
Include ports.conf
# Include of directories ignores editors' and dpkg's backup files,
# Include generic snippets of statements
Include conf.d/
# Include the virtual host configurations:
Include sites-enabled/

配置文件关系
1. *-enabled 里面都是 连接文件,指向 available. 如:
$ll mods-enabled/alias.conf
lrwxrwxrwx 1 root root 28 Dec 24 2013 mods-enabled/alias.conf -> ../mods-available/alias.conf

sites-enabled sites-available 是存放apache功能模块的配置文件和链接的,当我用apt-get install php5安装了PHP模块后,在这两个目录里就有了php5.load、php5.conf和指向这两个文件的链接。这种目录结果对于启用、停用某个 Apache模块是非常方便的。
所以想enable 某个mod 或者 site, 直接在xx-enabled 建立连接指向xx-available
2. httpd.conf
主要用户配置文件, 一般虚拟主机、访问权限等都是在这里修改
3. ports.conf
这里面设置了Apache使用的端口。如果需要调整默认的端口设置,建议编辑这个文件。
4. conf.d/*
其他配置文件
5. sites-enabled/*
这个是很多人忽略的配置文件,/var/www的默认位置就是从这里定义。 定义其他可参照sites-available/default 中定义。

举例: apache2 二级域名设置:

1. 确认apache2 安装成功
2. 创建目标文件:

sudo mkdir /etc/apache2/BobTest
sudo vim /etc/apache2/index.html
<h1>
For Bob test! Thanks!
</h1>

保存退出: :wq
3. 修改httpd.conf:

#This is a sample for Bob to setup secpmdaru domain name of apache2
Alias /bobtest /etc/apache2/BobTest/

<Directory /etc/apache2/BobTest>
        Order deny,allow
        Allow from all
</Directory>

4. 重启apache2

sudo /etc/apache2 restart

5. open browser –> localhost/bobtest

参考:
http://www.cnblogs.com/ylan2009/archive/2012/02/25/2368028.html
http://httpd.apache.org/docs/2.4/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值