linux小记:Ubuntu和Arch下的Apache

Apache2在Ubuntu和Arch下,配置文件的组织方式差别还是挺大的。小记一下,因为我过不久肯定就会忘的=.=

Ubuntu

在Ubuntu下,配置目录在/etc/apache2。在此目录下,主要配置文件是apache2.conf,但是为了更清晰,在Ubuntu上Apache的配置文件是拆分了的,最后在apache2.conf中都Include了进来。比如:

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

Apache的配置文件主要拆出来的有这几块:ports.conf/sites/conf/mods,具体目录结构如下:

/etc/apache2/
|-- apache2.conf
|       `--  ports.conf
|-- mods-enabled
|       |-- *.load
|       `-- *.conf
|-- conf-enabled
|       `-- *.conf
|-- sites-enabled
|       `-- *.conf

ports.conf

其中ports.conf里面设置了监听的端口,默认已经有了Listen 80

sites-avaliable & sites-enable

sites分为sites-availablesites-enable两个文件夹。一般是available里面放配置文件,代表所有可用的站点,enable里面放软链接,链到available里面的配置文件,则这个配置文件就启用了。

Note: 切记软链接的时候一定要用全路径,如ln -s /etc/apache2/sites-available/puppy.conf /etc/apache2/sites-enable/,不然会出现迷之错误。

sites就是站点的意思。比如我有两个站点,apache-default.confpuppy.conf,前者设置为端口81,并在开头写上Listen 81,虽然理论上应该写到ports.conf文件中,不过写在这里会更清晰。不想要这个站点的时候直接删了这个文件就行了。
比如,apache的默认配置文件,我们把端口改成81

Listen 81
<VirtualHost *:81>
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

站点配置文件中除了修改对应的端口号,还要修改DocumentRoot,即站点放置的位置。Ubuntu下Apache站点放置位置在/var/www,比如默认站点在/var/www/html。我们可以将puppy站点放置目录为/var/www/puppy,这样在访问我们的Apache地址www.xxx.com.cn(如果有域名的话。否则写架设Apache服务器的IP)时对应的就是/var/www/puppy[/index.html]。访问www.xxx.com.cn:81对应的就是Apache的站点/var/www/html

conf / mods

confmodssites类似,也是由availableenable构成。
这些东西最后都includeapache2.conf中。

DocumentRoot的概念

apache2.conf里面有<Directory blabla_path>或者<File blabla_file>,里面设置的是一些权限的问题,即给开放的站点加上权限。
比如apache2.conf默认对几个地方进行了设置:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Document Roots: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.

启动方式

Ubuntu启动Apache的方式为service apache2 start,或者用systemctl或者/etc/init.d的启动方式都行。

Arch

Arch上Apache的默认配置文件在/etc/httpd下,比如配置文件在conf文件夹中。默认配置文件为/etc/httpd/conf/httpd.conf,其他配置文件在/etc/httpd/conf/extra文件夹里,也是通过Include引用进来的,比如:

# User home directories
Include conf/extra/httpd-userdir.conf
# Various default settings
Include conf/extra/httpd-default.conf

装完php后就得把php的配置文件Include进来:

Include conf/extra/php7_module.conf

装完phpmyadmin也一样:

Include conf/extra/phpmyadmin.conf

其实这样做的话,个人感觉会把主配置文件httpd.conf搞得有点儿庞杂,不像Ubuntu下的主配置文件apache.conf那么简洁。

ArchWiki上Apache的配置页面httpd.conf有比较详细的介绍,比如DocumentRoot "/srv/http"是Arch下Apache的默认站点目录。ServerRoot "/etc/httpd"是配置文件的目录。这些都和Ubuntu上的不同。Listen 80也在这里面。ServerAdmin shininglhb@163.com可以设置邮箱,当页面挂了的时候会显示给用户。

当然这里面也有关于DocumentRootDirectory的设置,比如默认的:

DocumentRoot "/srv/http"
<Directory "/srv/http">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

构建多个站点

如果我们想构建多个站点,且希望更方便的维护,建议为每一个虚拟主机创建一个配置文件并文件存储到一个文件夹中 /etc/httpd/conf/vhosts中。并在 /etc/httpd/conf/httpd.conf中注释掉Include conf/extra/httpd-vhosts.conf这一行。
比如我们新建一个puppy的站点,监听端口为81,就新建一个/etc/httpd/conf/vhosts/puppy.dom,格式按照下面这个示例进行替换即可:

<VirtualHost domainname1.dom:80>
    ServerAdmin webmaster@domainname1.dom
    DocumentRoot "/home/user/http/domainname1.dom"
    ServerName domainname1.dom
    ServerAlias domainname1.dom
    ErrorLog "/var/log/httpd/domainname1.dom-error_log"
    CustomLog "/var/log/httpd/domainname1.dom-access_log" common

    <Directory "/home/user/http/domainname1.dom">
        Require all granted
    </Directory>
</VirtualHost>

这一点跟Ubuntu上新建站点的配置文件没有什么区别。
最后别忘了在httpd.conf中加入:

Include conf/vhosts/puppy.dom

启动方式

Arch使用的是systemd,所以使用systemctl start httpd.service来启动Apache。
Ubuntu配置文件是apache2.conf,启动参数是apache2;Arch配置文件是httpd.conf,启动参数是httpd.service

两个不同的发行版有不同的配置组织方式。不过总体感觉,Ubuntu下的Apache的配置方式更整洁一点儿。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Arch LinuxUbuntu是两种不同的Linux发行版,它们有一些区别,包括以下方面: 1. 安装和包管理:Arch Linux采用了滚动更新的方式,用户可以通过Arch Linux的安装程序自定义安装系统,并使用其包管理器pacman来管理软件包。而Ubuntu则提供了一个易于使用的安装程序,并使用apt包管理器来管理软件包。 2. 软件库和软件更新:Arch Linux提供了一个庞大的软件库,其中包含了大量的软件包,并且以滚动更新的方式持续提供最新的软件版本。Ubuntu也有广泛的软件库,但由于其发布周期,软件包的更新相对较慢。 3. 用户定制性:Arch Linux被认为是一种面向有经验的Linux用户的发行版,它提供了完全的定制性,用户可以根据自己的需求选择安装和配置软件。而Ubuntu更注重易用性和用户友好性,提供了更多的默认设置和图形化工具。 4. 社区支持和文档资源:Ubuntu拥有庞大的用户社区和开发者社区,提供了广泛的文档资源、教程和支持。Arch Linux的社区相对较小,但也有一些活跃的用户社区和文档资源,同时它鼓励用户自己解决问题并参与社区贡献。 总之,Arch LinuxUbuntu在安装和包管理、软件库、用户定制性以及社区支持等方面存在一些区别。选择哪个发行版取决于个人的需求和技术水平。如果您喜欢更高度的定制性和滚动更新的软件,可以选择Arch Linux;如果您更注重易用性和广泛的社区支持,可以选择Ubuntu

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值