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

来源:互联网 发布:3b线切割手工编程 编辑:程序博客网 时间:2024/05/17 04:28

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/*.loadInclude mods-enabled/*.conf# Include all the user configurations:Include httpd.conf# Include ports listingInclude ports.conf# Include of directories ignores editors' and dpkg's backup files,# Include generic snippets of statementsInclude 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/BobTestsudo 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 apache2Alias /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
原创粉丝点击