Apache configuration file
directory where the configuration file is located:
/etc/httpd/conf/
Master configuration file:
httpd.conf
Configuration files in the previous version:
Resource configuration file: srm.conf
Access Permissions Profile: access.conf
AccessConfig and ResourceConfig
To be compatible with older versions of Apache, the Apache server looks for and reads the contents of the access.conf and srm.conf files on each boot. The AccessConfig and ResourceConfig directives in the httpd.conf file specify the location of the access.conf and srm.conf files, with the default values:
AccessConfig conf/access.conf ResourceConfig conf/srm.conf
For security reasons, you can set it to:
Accessconfig/dev/null
Resourceconfig/dev/null
Specify that these two files are empty device files "/dev/null", which avoids the malicious modification of access.conf and srm.conf files on the system configuration.
What's configured
1. Global variables
2. Configuring the master server
3. Configure the Virtual host
Global variables
1. Select the server Startup type ServerType
ServerType Standalone | inetd
ServerType is used to define the operating mode of the Apache server, the default value is standalone to run independently of the server, as set to inetd by the XINETD server is responsible for the Apache server boot.
2. Set the root directory of the server ServerRoot
ServerRoot "/ETC/HTTPD"
The serverroot is used to specify the root directory of the Apache server's configuration files and log files, and the default is directory "/ETC/HTTPD".
3. Set lock file <ifmodule! Mpm_winnt.c>
4. Set the internal data of the Scoreboardfile maintenance process, which is usually not required.
5. Set Pidfile Specifies the file that stores the PID of the httpd parent process
Pidfile/var/run/httpd.pid
The pidfile is used to specify the file location where the httpd process number (PID) is recorded, and the default value is "/var/run/httpd.pid".
6. Set time-out timeout timeout
Timeout 300
Specifies the number of seconds the site responds. If the data has not been received or sent over this period of time, the connection will be disconnected.
KeepAlive on| Off
Enabling this means allowing the connection to be maintained so that each connection can make multiple requests. Avoid establishing a connection with the server every time a file is requested.
Maxkeepaliverequests 100
The number of requests per connection, set to 0 indicates an unlimited number, and the default value is 100.
KeepAliveTimeout 15
The time between successive two requests is considered a connection outage if more than 15 seconds have not arrived.
7. Set number of server processes <ifmodule Prefork.c>
<ifmodule prefork.c>
Minspareservers 5
Maxspareservers 20
The number of httpd processes that provide browsing services needs to vary with the number of connections, so it is necessary to keep several idle httpd processes waiting for new connection requests at any time. If the number of idle processes is less than 5 (the default), it means that there are too few idle processes to increase it to 5, and if more than 20 (the default), it means that there are too many idle processes to reduce them to 20.
Startservers 8
When the Apache server starts, the number of httpd processes, the default value is 8.
MaxClients 150
A colleague with too many accesses can degrade system access performance, set this parameter to limit the maximum number of simultaneous connections, and the default value is 150.
</ifmodule>
8. Set Address bindings Listen
Listen 12.34.56.78:80
Used to set the Apache server to listen for connection requests on the specified IP and/or port.
Listen 80
Specifies the port number that the Apache server listens on.
9. Select Module LoadModule ...
Loading module directives
The Apache server uses the mechanism of dynamic shared objects (Dso,dynamic shared object), which is capable of loading the appropriate modules according to actual needs when starting the Apache server.
The relevant directives for loading modules are:
LoadModule
Clearmodulelist
Addmodule
The loadmodule instruction is used to dynamically load the module and plug the module into the Apache server.
Grammar:
LoadModule Module Name module file path full name
Instance:
LoadModule Status_module modules/mod_status.so
Clearmodulelist
The clearmodulelist instruction is used to empty the list of modules built into the Apache server. This directive is usually used to clear the list, and then use the ADDMODULE directive to add modules to the module list.
Addmodule
The addmodule directive is used to add a new module name to the module list.
Grammar:
Addmodule module
Instance:
Addmodule MOD_STATUS.C
10. Configuring status information Extendedstatus
Configuring the primary server
1. Set user and group users and groups
User Apache group Apache sets httpd with which users account and group to start, using Apache Users and groups by default.
2. Set Email address ServerAdmin
ServerAdmin [email protected]
The server administrator's email address, which will be sent to this email address when the server is running in error.
3. Set the server name ServerName
ServerName localhost
Set the name of the host, which will be sent to the remote connector to replace the actual name of the Apache host installation. The default value is localhost, with the # number at the beginning of the line, to turn off this feature.
4. Set formal name Usecanonicalname
5. Set up the document directory DocumentRoot
DocumentRoot "/var/www/html"
Specifies the document root directory where the Apache server holds the Web pages.
6. Set access options and overwrite <directory/>options ...
Container Directives (container directive) are usually included in the <> brackets and are easier to identify. Conditional Directives <IfDefine> and <IfModule> are not container directives, they are exceptions. The commonly used container directives are:
<Directory>
<Files>
<Location>
<VirtualHost>
<directory> </Directory>
<directory/> Setting "/" Access to the root directory
Options FollowSymLinks
AllowOverride None
</Directory> Directory Property Set End
Use <directory>. </Directory> sets the access permissions for the specified directory, which can include:
Options
AllowOverride
Order
Allow
Deny
Five attributes.
Options Properties
Options followsymlinks Indexes MultiViews
Options can be combined to set the following:
All: Users can do everything in this directory.
EXECCGI: Allows CGI programs to be executed in this directory.
FollowSymLinks: The server can use the file or directory that the symbolic link points to.
Indexes: The server can generate a list of files for this directory.
None: Access to this directory is not allowed.
AllowOverride
AllowOverride None
AllowOverride determines whether or not to read the. htaccess file in the directory, depending on the set value, to change the permissions that were previously set.
All: Read the contents of the. htaccess file and modify the original access permissions.
None: Do not read the. htaccess file
To prevent users from setting up their own. htaccess files, modify the access permissions, and the default settings in the http.conf file are: allowoverride None.
Accessfilename
Accessfilename filename
The accessfilename directive specifies the file name that protects the directory settings file, with the default value of ". htaccess".
Accessfilename. ACL
Allow
Setting a host that allows access to the Apache server
Allow from all
Allow access to all hosts
Allow from 202.96.0.97 202.96.0.98
Allow access from the specified IP address host
Deny sets deny access to the Apache server deny from all deny access to all hosts deny from 202.96.0.99 202.96.0.88 deny access to the specified IP address host
Order Order Allow,deny Order specifies the order of allow and deny.
7. Set up user directory Userdir
Userdir public_html
Userdir is used to set the directory where the user's profile is stored, which defaults to the "public_html" directory, which is/home/anyuser/public_html.
8. Set Directory index DirectoryIndex
DirectoryIndex index.html index.htm index.shtml index.php
The DIRECTORYINDEX directive is used to specify the default index file name in the directory, specifying multiple file names, separated by a space between 22. The default value is index.html.
9. Set access Control Accessfilename
Accessfilename. htaccess
Defines the file name of the access control file under each directory, by default. htaccess; Edit the file as follows:
<Files>...</Files>
The <Files> container contains instructions that apply only to the specified file, which should be specified by the file name (using the wildcard character if necessary).
Instance:
<files = "^\.ht" >
Order Allow,deny
Deny from all
</Files>
<location> </Location>
The <Location> container contains instructions that apply only to a specific URL.
Instance:
<Location/server-status>
SetHandler Server-status
Order Deny,allow
Allow from 127.0.0.1
Deny from all
</Location>
10. Set MIME type file Typesconfig
11. Configuration log File Hostnamelookups
12. Setting Up Server information Servertokens
13. Setting Directory aliases Alias
Alias to set the path alias
alias/doc//usr/share/doc/
Set the path alias to "/usr/share/doc/" to "/doc/"
14. Set index options addiconbyencoding produces different icons for different types of files in the catalog index.
15. Define the encoding and language addencoding to define MIME types for some compressed files.
16. Add MIME type and processing type AddType
17. Custom Error Response ErrorDocument
18. Set Browser response Browsermatch
Establish a virtual Web site
1. IP-based virtual host configuration
Instance:
Add a different IP address:
# ifconfig eth0:0 192.168.0.2
# route Add-host 192.168.0.2 eth0:0
Edit the/etc/httd/conf/httpd.conf file to add the following:
<virtualhost 192.168.0.2>
ServerAdmin[email protected]
Documentroot/var/www/mailserver
ServerName mail.astronomy.org
Errorlog Logs/mailserver Error_log
Customlog Logs/mailserver-access_log Common
</VirtualHost>
Restart Service
#/usr/local/apache2/bin/apachectl Restart
2, domain-based virtual host configuration
Example: adding related host records in DNS; modifying the httpd.conf file
Namevirtualhost 192.168.0.1
<virtualhost 192.168.0.1>
ServerAdmin[email protected]
Documentroot/var/www/mailserver
ServerName mail.astronomy.org
Errorlog Logs/mailserver Error_log
Customlog Logs/nameserver Access_log Common
</VirtualHost>
Restart Service
#/usr/local/apache2/bin/apachectl Restart
Apache Configuration Parameters