• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Apache HTTP server – most commonly used configuration directives

by admin

The main configuration file for Apache is /etc/httpd/conf/httpd.conf. Apache runs as installed, but you can modify configuration directives in this file to customize Apache for your environment. Some of these directives are described in the post below.

Listen [IP address:]port

Tells the server to accept incoming requests on the specified port or IP address and port combination. By default, the server responds to requests on all IP interfaces on port 80. If you specify a port number other than 80, a request to the server must include the port number (as in www.example.com:8080). This is a required directive. Examples are as follows:

Listen 80
Listen 192.168.2.1:8080

ServerName FQDN[:port]

Specifies the fully qualified domain name or IP address of the server and an optional port that Apache listens on. The FQDN must be able to be resolved by DNS. If no FQDN is specified, Apache performs a DNS reverse name lookup on the IP address. If no port is specified, the server uses the port from the incoming request, as shown in the following example:

ServerName www.example.com:80

ServerRoot directory-path

The top of the directory hierarchy under which the Apache server’s configuration, error, and log
files are kept. The default is /etc/httpd. Do not add a slash at the end of directory-path:

ServerRoot /etc/httpd

DocumentRoot directory-path

The top of the directory hierarchy that holds the Apache server content. Do not end the path name with a slash. The apache user needs read access to any files and execute access to the directory and any subdirectories in the hierarchy. The following is the default:

DocumentRoot /var/www/html

UserDir directory-path | disabled | enabled user-list

Allows users identified by the user-list argument to publish content from their home directories. The directory-path is the name of a directory in a user’s home directory from which Apache publishes content. If directory-path is not defined, the default is ~/public_html. The following example enables this feature for user user01. Assuming that the ServerName is www.example.com, browsing to http://www.example.com/~user01 displays the user01 user’s webpage.

UserDir enabled user01

ErrorLog filename | syslog[:facility]

Specifies the name of the file, relative to ServerRoot, that Apache sends error messages to. Alternatively, syslog specifies that Apache must send errors to rsyslogd. The optional facility argument specifies which rsyslogd facility to use. The default facility is local7.

ErrorLog logs/error_log

LoadModule module filename

Apache, like the Linux kernel, uses external modules to extend functionality. These modules are called dynamic shared objects (DSOs). The module argument is the name of the DSO and filename is the path name of the module, relative to ServerRoot. More than 60 modules are included with Apache, and more than 50 of these are loaded by default. An index of all the modules is available at http://httpd.apache.org/docs/2.4/mod/.

LoadModule auth_basic_module modules/mod_auth_basic.so

Allow from All | host [host …]

Specifies which clients can access content. All serves content to any client. Alternatively, you
can list the specific hosts that are allowed access to content.

Deny from All | host [host …]

Specifies which clients are not allowed access to content.

Order deny,allow | allow,deny

Specifies the order in which Allow and Deny directives are evaluated. deny,allow evaluates deny directives first and then allow directives. The following example grants access to clients from the example.com domain only, by first denying access to all and then allowing it from .example.com:

Order deny,allow
Deny from all
Allow from .example.com

Timeout num

Specifies the number of seconds Apache waits for network operations to finish. The default is 60.

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. pacman-mirrors Command Examples in Linux
  2. dircolors: Output commands to set the LS_COLOR environment variable and style ls, dir, etc
  3. Understanding System Security Services Daemon (SSSD)
  4. dpkg Command Examples in Linux
  5. How to use mdadm to create a software mirror on top of multipath devices
  6. How to enable md5 Hashing in Linux
  7. uuidd: command not found
  8. arp-scan: Send ARP packets to hosts (specified as IP addresses or hostnames) to scan the local network
  9. lvsd Command Examples in Linux
  10. How to Schedule Jobs with ‘at’ command under Linux

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright