Apache 基金会的开源项目,是一个高性能、功能强大、安全可靠、灵活的开放源码 Web 服务软件
官方宣称:与 Apache 2.2.x 相比,Apache 2.4.x 提供了很多性能方面的提升,包括支持更大流量、更好地支持云计算、利用更少的内存处理更多的并发等。
除此之外,还包括性能提升、内存利用、异步I/O的支持、动态反向代理设置、与时间驱动的 Web 服务器相当或更好的性能、更强大的处理资源分配能力,更便捷的缓存支持以及可定制的高速服务器和代理等。
其它的功能还包括更简单的错误分析、更灵活的设置项、更强大的验证机制和更完整的文档。
Apache 2.4.x 比许多以速度见长的 Web 服务器更快,例如:Nginx。
应用场景:

  • 运行静态页面和图片
  • 结合 PHP 引擎运行 PHP 程序
  • 结合 Tomcat 运行 JAVA\JSP 程序
  • 做代理、负载平衡

    编译安装

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    yum install -y expat-devel
    wget https://udomain.dl.sourceforge.net/project/expat/expat/2.5.0/expat-2.5.0.tar.gz
    tar -zxvf expat-2.5.0.tar.gz
    cd expat-2.5.0
    ./configure --prefix=/app/service/apache/expat
    make && make install

    wget https://dlcdn.apache.org//apr/apr-1.7.2.tar.gz
    tar -zvxf apr-1.7.2.tar.gz
    cd apr-1.7.2
    ./configure --prefix=/app/service/apache/apr
    make && make install

    wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
    tar -zxvf apr-util-1.6.3.tar.gz
    cd apr-util-1.6.3
    ./configure \
    --prefix=/app/service/apache/apr-util \
    --with-apr=/app/service/apache/apr \
    --with-expat=/app/service/apache/expat
    make && make install

    wget https://archive.apache.org/dist/httpd/httpd-2.4.54.tar.gz
    tar -zxvf httpd-2.4.54.tar.gz
    cd httpd-2.4.54
    ./configure \
    --prefix=/app/service/apache/httpd24 \
    --sysconfdir=/app/conf/apache/httpd24 \
    --enable-modules=most \
    --enable-mods-shared=most \
    --enable-mpms-shared=all \
    --enable-deflate \
    --enable-expires \
    --enable-ssl \
    --enable-rewrite \
    --with-apr=/app/service/apache/apr \
    --with-apr-util=/app/service/apache/apr-util \
    --with-mpm=event
    make && make install

    应用配置

    修改配置,文件位置:conf/httpd.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    ServerRoot "/app/service/apache/httpd24"
    Listen 8080

    #各模块说明详解 - https://httpd.apache.org/docs/2.4/mod/
    # LoadModule foo_module modules/mod_foo.so
    LoadModule mpm_event_module modules/mod_mpm_event.so
    #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
    #LoadModule mpm_worker_module modules/mod_mpm_worker.so
    LoadModule authn_file_module modules/mod_authn_file.so
    #LoadModule authn_dbm_module modules/mod_authn_dbm.so
    #LoadModule authn_anon_module modules/mod_authn_anon.so
    #LoadModule authn_dbd_module modules/mod_authn_dbd.so
    #LoadModule authn_socache_module modules/mod_authn_socache.so
    LoadModule authn_core_module modules/mod_authn_core.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_user_module modules/mod_authz_user.so
    #LoadModule authz_dbm_module modules/mod_authz_dbm.so
    #LoadModule authz_owner_module modules/mod_authz_owner.so
    #LoadModule authz_dbd_module modules/mod_authz_dbd.so
    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule access_compat_module modules/mod_access_compat.so
    LoadModule auth_basic_module modules/mod_auth_basic.so
    #LoadModule auth_form_module modules/mod_auth_form.so
    #LoadModule auth_digest_module modules/mod_auth_digest.so
    #LoadModule allowmethods_module modules/mod_allowmethods.so
    #LoadModule file_cache_module modules/mod_file_cache.so
    #LoadModule cache_module modules/mod_cache.so
    #LoadModule cache_disk_module modules/mod_cache_disk.so
    #LoadModule cache_socache_module modules/mod_cache_socache.so
    #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
    #LoadModule socache_dbm_module modules/mod_socache_dbm.so
    #LoadModule socache_memcache_module modules/mod_socache_memcache.so
    #LoadModule socache_redis_module modules/mod_socache_redis.so
    #LoadModule watchdog_module modules/mod_watchdog.so
    #LoadModule macro_module modules/mod_macro.so
    #LoadModule dbd_module modules/mod_dbd.so
    #LoadModule dumpio_module modules/mod_dumpio.so
    #LoadModule buffer_module modules/mod_buffer.so
    #LoadModule ratelimit_module modules/mod_ratelimit.so
    LoadModule reqtimeout_module modules/mod_reqtimeout.so
    #LoadModule ext_filter_module modules/mod_ext_filter.so
    #LoadModule request_module modules/mod_request.so
    #LoadModule include_module modules/mod_include.so
    LoadModule filter_module modules/mod_filter.so
    #LoadModule substitute_module modules/mod_substitute.so
    #LoadModule sed_module modules/mod_sed.so
    #LoadModule deflate_module modules/mod_deflate.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule log_config_module modules/mod_log_config.so
    #LoadModule log_debug_module modules/mod_log_debug.so
    #LoadModule logio_module modules/mod_logio.so
    LoadModule env_module modules/mod_env.so
    #LoadModule expires_module modules/mod_expires.so
    LoadModule headers_module modules/mod_headers.so
    #LoadModule unique_id_module modules/mod_unique_id.so
    LoadModule setenvif_module modules/mod_setenvif.so
    LoadModule version_module modules/mod_version.so
    #LoadModule remoteip_module modules/mod_remoteip.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_connect_module modules/mod_proxy_connect.so
    LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
    #LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
    #LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
    #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
    #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    #LoadModule proxy_express_module modules/mod_proxy_express.so
    #LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
    #LoadModule session_module modules/mod_session.so
    #LoadModule session_cookie_module modules/mod_session_cookie.so
    #LoadModule session_dbd_module modules/mod_session_dbd.so
    #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
    #LoadModule ssl_module modules/mod_ssl.so
    #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
    #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
    #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
    #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
    LoadModule unixd_module modules/mod_unixd.so
    #LoadModule dav_module modules/mod_dav.so
    LoadModule status_module modules/mod_status.so
    LoadModule autoindex_module modules/mod_autoindex.so
    #LoadModule info_module modules/mod_info.so
    #LoadModule cgid_module modules/mod_cgid.so
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    #LoadModule vhost_alias_module modules/mod_vhost_alias.so
    #LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule dir_module modules/mod_dir.so
    #LoadModule actions_module modules/mod_actions.so
    #LoadModule speling_module modules/mod_speling.so
    #LoadModule userdir_module modules/mod_userdir.so
    LoadModule alias_module modules/mod_alias.so
    #LoadModule rewrite_module modules/mod_rewrite.so

    <IfModule unixd_module>
    User daemon
    Group daemon
    </IfModule>

    ServerAdmin work@yuwei.cc
    ServerName localhost
    ServerAlias https://yuwei.cc

    <Directory />
    AllowOverride none
    Require all denied
    </Directory>

    DocumentRoot "/app/service/apache/httpd24/htdocs"
    <Directory "/app/service/apache/httpd24/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>

    <IfModule dir_module>
    DirectoryIndex index.html
    </IfModule>

    <Files ".ht*">
    Require all denied
    </Files>


    ErrorLog "logs/error_log"
    LogLevel warn

    <IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" common
    </IfModule>

    <IfModule alias_module>
    ScriptAlias /cgi-bin/ "/app/service/apache/httpd24/cgi-bin/"
    </IfModule>

    <IfModule cgid_module>

    </IfModule>

    <Directory "/app/service/apache/httpd24/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
    </Directory>

    <IfModule headers_module>
    RequestHeader unset Proxy early
    </IfModule>

    <IfModule mime_module>
    TypesConfig /app/conf/apache/httpd24/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    </IfModule>

    #MIMEMagicFile /app/conf/apache/httpd24/magic
    #ErrorDocument 500 "The server made a boo boo."
    #ErrorDocument 404 /missing.html
    #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
    #ErrorDocument 402 http://www.example.com/subscription_info.html
    # MaxRanges: Maximum number of Ranges in a request before
    # returning the entire resource, or one of the special
    # values 'default', 'none' or 'unlimited'.
    # Default setting is to accept 200 Ranges.
    #MaxRanges unlimited
    #EnableMMAP off
    #EnableSendfile on
    # Server-pool management (MPM specific)
    #Include /app/conf/apache/httpd24/extra/httpd-mpm.conf
    # Multi-language error messages
    #Include /app/conf/apache/httpd24/extra/httpd-multilang-errordoc.conf
    # Fancy directory listings
    #Include /app/conf/apache/httpd24/extra/httpd-autoindex.conf
    # Language settings
    #Include /app/conf/apache/httpd24/extra/httpd-languages.conf
    # User home directories
    #Include /app/conf/apache/httpd24/extra/httpd-userdir.conf
    # Real-time info on requests and configuration
    #Include /app/conf/apache/httpd24/extra/httpd-info.conf
    # Virtual hosts
    #Include /app/conf/apache/httpd24/extra/httpd-vhosts.conf
    # Local access to the Apache HTTP Server Manual
    #Include /app/conf/apache/httpd24/extra/httpd-manual.conf
    # Distributed authoring and versioning (WebDAV)
    #Include /app/conf/apache/httpd24/extra/httpd-dav.conf
    # Various default settings
    #Include /app/conf/apache/httpd24/extra/httpd-default.conf

    <IfModule proxy_html_module>
    Include /app/conf/apache/httpd24/extra/proxy-html.conf
    </IfModule>

    <IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
    </IfModule>

    <VirtualHost *:8080>
    ServerAdmin work@yuwei.cc
    DocumentRoot "/app/service/apache/httpd24/htdocs"
    ServerName localhost
    ServerAlias https://yuwei.cc
    ErrorLog "logs/error_log"
    CustomLog "logs/access_log" common
    ProxyPreserveHost On
    ProxyPass /api http://127.0.0.1:9090
    ProxyPassReverse /api http://127.0.0.1:9090
    </VirtualHost>
    conf/extra/httpd-vhosts.conf

    基本运维

    1
    2
    3
    4
    5
    6
    7
    8
    9
    /app/service/apache/httpd24/bin/httpd -v
    #启动服务
    /app/service/apache/httpd24/bin/httpd
    #重启服务
    /app/service/apache/httpd24/bin/httpd -k restart
    #关闭服务
    /app/service/apache/httpd24/bin/httpd -k stop
    #服务进程
    ps -ef | grep httpd