First, the basic configuration
Lab Environment: Centos6.8
Apache Version: 2.2.15
First, the basic configuration
1, installation httpd
Yum Install-y httpd
2. Edit the configuration file/etc/httpd/conf/httpd.conf
vim /etc/httpd/conf/httpd.confservertokens os # Server corresponding host header information, display Apache version and operating system name serverroot "/ETC/HTTPD" #指定服务器主配置文件和日志文件的位置Timeout 60 #在指定时间内没有收到或发出任何数据则断开连接, Units of seconds keepalive on #是否启用长连接MaxKeepAliveRequests 100 #当启用长连接时, the maximum number of requests that can be connected at a time keepalivetimeout 15 #启用长连接时, Specifies the maximum time interval for adjacent two requests in a single connection, which is disconnected <ifmodule prefork.c> # Using the Prefork working model startservers 8 # The number of daemons that started when it was opened minspareservers 5 #设置最少空闲进程, A new process maxspareservers 20 #设置最多空闲进程 is created when the idle process is less than the specified Some serverlimit 256 # are removed when the idle process is more than the rule Set the maximum number of simultaneous connections allowed by the server maxclients 256 #设置同一时间允许的最大客户端连接数MaxRequestsPerChild 4000 #设置每个子进程能处理的最大连接数量 </ifmodule>directoryindex index.html index.html.var #设置网站默认文档Include conf.d/*.conf #将指定文件包含进来User apache #设置运行apache服务的用户Group apache #设置运行apache服务的组ServerAdmin [email protected] #设置管理员的邮箱, email the Administrator documentroot "/var/www/html" when there is a problem with the Apache service # Set the root location of the Web page # Set properties for a specific directory <Directory "/var/www/html" > Options followsymlinks #FllowSymLinks: Allows access to the file of a symbolic link, which means that you can access files that are not in this directory indexes: The file list for the current directory is generated when the file specified in DirectoryIndex is not found in the directory MultiViews: if the path requested by the client may correspond to multiple types of files, the server will automatically select a file that best matches the client's requirements, depending on the client's request. For example, in the file folder of the server site, there are two files named Hello.jpg and hello.html, at which time the user enters Tttp://localhost/file/hello, if there is no Hello subdirectory under the file folder, The server will then attempt to find a file with the form hello.* under the file folder and then return the hello.jpg or hello.html that best matches the request, depending on the user's request. allowoverride none # Do not read the contents of the. htaccess configuration file order allow,deny #先执行allow访问控制规则, then execute DENY&NBsp; allow from all #放行所有 </directory>hostnamelookups off # Set the server to record the IP address or hostname of the client, log the IP when off, and record the host name when on errorlog logs/error_log #设置错误日志保存位置
3. Start httpd Service
Service httpd Start
Second, the realization of user authentication and authorization
1, create authentication password file, and add user Lzs, password is 123456 and user zsgg, password is ZSGG, password is encrypted with MD5
Htpasswd-cm/var/www/html/passwd/test Lzs 123456htpasswd-m/var/www/html/passwd/test zsgg zsgg
2. The owner of the modified authentication password file is Apache
Chown Apache.apache/var/www/html/passwd/test
3. Edit/etc/httpd/conf/httpd.conf
<directory "/var/www/html" > AllowOverride authconfig #启用认证 authtype Basic #设置认证方式 AuthName "Please enter user name password" #设置提示信息 authuserfile/var/www/passwd/test #指定认证口令文件 require Valid-user #设置认证口令文件中的所有用户都 Access to </Directory>
Three, virtual directory
Edit/etc/httpd/conf/httpd.conf
Alias/lzs "/var/www/lzs/"
The server/var/www/lzs directory can be accessed by entering Http://x.x.x.x/lzs on the client
Four, virtual host
Premise: DocumentRoot "/var/www/html" should be commented out when configuring the virtual host
4.1. IP address-based virtual host
<virtualhost 192.168.0.1:80> ServerAdmin [email protected] documentroot/www/html/www1.lzs.com ServerName W ww1.lzs.com errorlog logs/www1.lzs.com-error_log customlog logs/www1.lzs.com-access_log common</virtualhost>& Lt VirtualHost 192.168.0.2:80> ServerAdmin [email protected] documentroot/www/html/www2.lzs.com ServerName www2. lzs.com errorlog logs/www2.lzs.com-error_log customlog logs/www2.lzs.com-access_log common</VirtualHost>
4.2. Port-based virtual host
<virtualhost 192.168.0.1:80> ServerAdmin [email protected] documentroot/www/html/www1.lzs.com ServerName W ww1.lzs.com errorlog logs/www1.lzs.com-error_log customlog logs/www1.lzs.com-access_log common</virtualhost>& Lt VirtualHost 192.168.0.1:8080> ServerAdmin [email protected] documentroot/www/html/www2.lzs.com ServerName www 2.lzs.com errorlog logs/www2.lzs.com-error_log customlog logs/www2.lzs.com-access_log common</VirtualHost>
4.3. Domain-based virtual host
1. Configure DNS server so that multiple domain names can be resolved to the same IP address
2. Edit/etc/httpd/conf/httpd.conf
Namevirtualhost 192.168.0.1:80 #启用基于域名的虚拟主机 <virtualhost 192.168.0.1:80> ServerAdmin [email protected] Docum entroot/www/html/www1.lzs.com ServerName www1.lzs.com errorlog logs/www1.lzs.com-error_log customlog logs/www1.l Zs.com-access_log common</virtualhost><virtualhost 192.168.0.1:80> ServerAdmin [email protected] Documen troot/www/html/www2.lzs.com ServerName www2.lzs.com errorlog logs/www2.lzs.com-error_log customlog Logs/www2.lzs . Com-access_log common</virtualhost>
This article is from the "a" blog, please make sure to keep this source http://lzs66.blog.51cto.com/9607068/1843262
Apache Server installation and configuration detailed