Crmgo Blog

http.conf Directives

http.conf Directives

ServerRoot The path to the Apache HTTP server executable files. Listen Sets the port and IP address that Apache listens on. By default, all browsers attempt to open an HTTP connection to the Apache server via port 80. If you set a different port number, such as 9031, then to open a page in…

http.conf Directives

ServerRoot Path to the executable files of the Apache HTTP server. Listen Sets the port and IP address that Apache listens on. By default, all browsers attempt to open an HTTP connection to the Apache server via port 80. If you set a different port number, such as 9031, you must specify the port after the page address using a colon, for example: http://localhost:9031. Additionally, this directive can specify a single IP address that Apache will handle (e.g., Listen 192.168.0.10:80) if the computer has two or more IP addresses. DocumentRoot This directive in httpd.conf defines the directory where the HTML and other files of a single site are located. If it is necessary to support two or more sites with a single Apache server, you should use the <VirtualHost></VirtualHost> container directive. When using virtual hosts, do not forget to configure access rights for the directory specified in the "DocumentRoot" line, as pages from this directory will be displayed to users who entered a domain not listed in VirtualHost. <Directory>
...
</Directory>

Directives specified within the Directory container will affect all files and folders in the specified directory. The path to the directory is specified immediately after the word Directory, for example: code block
<Directory "C:/apache2.2.19/htdocs"> ... directives ... </Directory>

configures the behavior of the specified directory. Instead of a directory name, you can use regular expressions. Options The Options directive determines which server features are available in a specific directory.

  • All - all options are allowed, except MultiViews (set by default).
  • None - all options are disabled.
  • ExecCGI - execution of CGI scripts is allowed.
  • FollowSymLinks - the server will follow symbolic links in this directory.
  • Includes - SSI (Server-Side Includes) is allowed.
  • IncludesNOEXEC - SSI is allowed, but #exec and #include commands in CGI scripts are blocked.
  • Indexes - if the requested URL corresponds to a directory, and there is nothing in this directory matching DirectoryIndex (e.g., Index.htm), the server will return a list of all files and directories in the directory.
  • MultiViews - content-negotiated MultiViews are allowed.
  • SymLinksIfOwnerMatch - the server will follow only those symbolic links for which the target file or directory has the same user ID as the link.
If multiple Options directives are applied to a directory, and then other options are applied to its subdirectory, the parent directory's options do not propagate to the subdirectory.
Example No. 1 - option inheritance:
<Directory "c:/www"> Options Indexes FollowSymLinks </Directory>

<Directory "c:/www/otherdir">
Options Includes
</Directory>

In this example, the c:/www directory and all its subdirectories, except c:/www/otherdir, are assigned "Indexes" and "FollowSymLinks". However, the c:/www/otherdir subdirectory and all its subdirectories are assigned only the "Includes" option.

Using the "+" and "-" symbols, you can add or remove any option for a subdirectory.
Example No. 2 - option inheritance:
<Directory "c:/www"> Options Indexes FollowSymLinks </Directory>

<Directory "c:/www/otherdir">
Options +Includes -Indexes
</Directory>

In this case, the c:/www/otherdir directory will have the "FollowSymLinks" option (added for the parent directory) and "Includes" (added using the "+" sign). The "Indexes" option is removed from the c:/www/otherdir directory using the "-" sign. AllowOverrideThe AllowOverride option tells Apache which directives in the .htaccess file are allowed (the filename ".htaccess" or any other is defined by the AccessFileName directive).

  • All - all directives are available (used by default).
  • None - .htaccess is not processed.
  • AuthConfig - allows the use of authorization directives (AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile, AuthName, AuthType, AuthUserFile, require, etc.).
  • FileInfo - allows the use of directives controlling document types (AddEncoding, AddLanguage, AddType, DefaultType, ErrorDocument, LanguagePriority, etc.).
  • Indexes - allows the use of directory indexing control directives (AddDescription, AddIcon, AddIconByEncoding, AddIconByType, DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName, IndexIgnore, IndexOptions, ReadmeName, etc.).
  • Limit - allows the use of basic access control directives (allow, deny, and order).
  • Options[=Option,...] - allows the use of directives controlling specific directory features (Options and XBitHack).
For performance and maximum security of the main directory of the Apache HTTP server "/", specified in the <Directory /> container, you should set AllowOverride to None: AllowOverride None.

Order The Order directive controls the default access state and the order in which access is granted or denied. Order can take 3 values:

  • Allow,Deny - access is denied by default, except for hosts specified in the line after Allow from.
  • Deny,Allow - access is granted by default, except for hosts specified in the line after Deny from.
  • Mutual-failure - access is granted only to hosts that are present in Allow and absent in Deny.
Most commonly, the values Allow, Deny, and Deny,Allow are used. The default value is determined by the last word (Allow or Deny). Between the words Allow and Deny in the Order directive, only a comma should be present, without spaces.
In examples 1-3, the opening and closing <Directory ...></Directory> containers are omitted for brevity; they are mandatory when configuring Apache.
In Example 1, the first line "Order Deny,Allow" sets the order for reading access rights: first, all rights that impose restrictions (Deny from...) are read, and then the allowing rights (Allow from) are processed. The default is set to Allow. The second line "Deny from all" denies access to all hosts for all domains. The third line, "Allow from apache.org", allows access to the apache.org domain.
Example 1 of access rights assignment
Order Deny,Allow Deny from all Allow from apache.org
The next example, Example 2, allows access only to the apache.org domain, except for the subdomain foo.apache.org (Deny from foo.apache.org). All other domains will be inaccessible.
Example 2 of access rights assignment
Order Allow,Deny Allow from apache.org Deny from foo.apache.org
Example 3 differs from Example 2 only in the Order value: "Deny,Allow" instead of "Allow,Deny". However, the logic of Apache's access rights provision changes in a somewhat unexpected way. Access will be open to absolutely all domains, including the subdomain foo.apache.org, which is explicitly denied by the line "Deny from foo.apache.org". This happens because the order of the lines "Allow from ..." and "Deny from ..." does not matter. The order in which rules are applied is defined by the Order directive. Based on this, Apache first denies access to foo.apache.org, and then overwrites this rule based on the directive "Allow from apache.org".
Example 3 of access rights assignment
Order Deny,Allow Allow from apache.org Deny from foo.apache.org
Example 4 denies access to the C:/www directory by default, even without using the line "Deny from ...".
Example 4 of access rights assignment
<Directory "C:/www"> Order Allow,Deny </Directory>

Additional information about the Allow, Deny, and Order directives can be found in the official Apache 2.2 documentation (eng). <VirtualHost>
...
</VirtualHost>

The <VirtualHost>...</VirtualHost> container is used for one Apache server to handle multiple websites. All directives written in the VirtualHost container apply exclusively to one site. One site (a set of files and directories) can be accessible via one or more domain(s) or IP address(es).
A special name _default_ can be defined, when this particular virtual host will match any IP address not explicitly specified in the declaration of another virtual host. If the _default_ virtual host declaration is absent in the server configuration and the request does not match any of the known virtual hosts, then the main server is used to respond, whose directory is specified in the DocumentRoot directive.
Inside each VirtualHost container, you can use almost any Apache directives, which allows you to configure each site in the most detailed manner.
Example of supporting 2 different sites with one Apache server
<VirtualHost *:80> ServerName first.loc ServerAlias www.first.loc DocumentRoot "c:/www/first.loc/public" ErrorLog "c:/www/first.loc/logs/error.log" </VirtualHost>

<VirtualHost *:80>
ServerName second.loc
ServerAlias www.second.loc
DocumentRoot "c:/www/second.loc/public"
ErrorLog "c:/www/second.loc/public"
</VirtualHost>

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.