Apache HTTP Server

Env

  • CentOS 6.x

Change Listen Port

  • /etc/httpd/conf/httpd.conf
    Listen 8081
    

Check running MPM

$ httpd -V

Server version: Apache/2.2.15 (Unix)
Server built:   Jul 18 2016 15:24:00
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Check Dynamically Loaded Module

$ httpd -M

Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authn_alias_module (shared)
 authn_anon_module (shared)
...

redirection / rewrite

mod_rewrite

언제 가장 필요한가?

  • ref: https://httpd.apache.org/docs/trunk/rewrite/avoid.html
  • The most common situation is which mod_rewrite is the right tool is when
    • the very best solution requires acces to the server configuration files
    • but I don't have that access
  • Some cofiguration directives are only avaialbe in the server configuration file.
  • So, if I am
    • in a hosting situation
    • only have.htaccess to work with
  • Then, I might need to resort to mod_rewrite

mod_alias

Redirect / RedirectMatch

  • providing a means to redirect one URL to another.
    • Redirect
    • RedirectMatch : allowing to include a regular expression in redirection criteria, provding many of the benefits of using RewriteRule in mod_rewrite.
  • this mod_alias is better solution for
    • simpe redirection ( best way over mod_rewrite )
    • Canonical Hostnames
    • http >> https
  • redirection will include GET parameters, but POST param will be discarded.

Alias in mod_alias

  • used to access documents stored in the local filesystem other than under the DocumentRoot

recommended way for canonical hostnames

core module

Directory

  • ref:
  • directory-path <Directory directory-path> ... </Directory>
    • ref: http://serverfault.com/questions/532630/is-the-apache-directory-directive-supposed-to-be-relative-to-the-documentroot-or
    • it can be either
      • full path to a directory
      • wild-card string using Unix shell-style matching
        • ?: any single character
        • *: any sequences of chacters
        • []: char ranges
        • None of above wildcards match a /, so <Directory "/*/public_html">
          • won't match /home/user/public_html
          • match <Directory "/home/*/public_html">
      • regular expression with the addition of the ~ character
    • directory-path is not a relative path based on DocumentRoot?.
      • e.g. 1 uses abolute full path
      • e.g. 2 means that abolute path /, root directoy in Linux
        # e.g. 1
        <VirtualHost>
            DocumentRoot /var/www
            <Directory /var/www>
            ...
        
        # e.g. 2
        <VirtualHost>
            DocumentRoot /var/www
            <Directory />
        
    • directory-path must be quoted if the path contains spaces. Otherwise, it may be quoted.
  • AllowOverride
    • disable checking .htaccess file not to allow overrides ( performance is better )
      <Directory "/">
        AllowOverride None
      </Directory>
      
  • Order

performance tunning

Configuration Principles

  • Directoy directive
    • quote directory path
    • use absolute full path

Security

Error

Monitor Apache Status

  • ref: http://www.tecmint.com/monitor-apache-web-server-load-and-page-statistics/
  • Update /etc/httpd/conf/http.conf
    • If VirtualHost is running, then Location content should be in VirtualHost as well.
      ExtendedStatus On
      
      Listen 9000
      <VirtualHost *:9000>
          <Location /server-status>
              SetHandler server-status
              Order deny,allow
              Allow from all 
          </Location>
      </VirtualHost>
      
  • the result can be browsered by links or lynx
    yum install links
    links http://127.0.0.1:9000/server-status
    

External References

Last modified 3 years ago Last modified on 11/27/16 22:15:27