Apache Http Server简单配置和使用

目的

如何在Ubuntu16.04配置和使用Apache Http Server。

简介

在Linux系统中,Apache是最常用的web应用服务器

内容

  1. 安装Apache Http Server,成功安装后,默认会启动服务器,端口号为80。

    1
    2
    $ sudo apt-get update
    $ sudo apt-get install apache2
  2. 默认的资源路径为/var/www/html

  3. Apache web server 系统安装目录/etc/apache2/

  4. /etc/apache2/apache2.conf 是主配置文件,它引用了所有的配置文件。

  5. /etc/apache2/sites-available/000-default.conf可以配置资源路径。

  6. /etc/apache2/ports.conf 设置端口号。

  7. Apache在Ubuntu系统下的操作需要加前缀才能执行/etc/init.d/

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # 查看服务器状态
    $ /etc/init.d/apache2 status
    # 启动服务器
    $ /etc/init.d/apache2 start
    # 重启服务器
    $ /etc/init.d/apache2 restart
    # 中断请求服务,停止服务器
    $ /etc/init.d/apache2 stop
    # 完成当前所有请求服务后,停止服务器
    $ /etc/init.d/apache2 graceful-stop
    # 重新加载配置文件
    $ /etc/init.d/apache2 reload
    # 和reload一样
    $ /etc/init.d/apache2 force-reload

参考资料
Ask Ubuntu
Apache official site
The difference between reload and force-reload