Apache server has four functions:
1. Basic webpage;
2. personal homepage;
3. Virtual Host;
4. webpage authentication;
If you do not know which one you are using, make the following changes:
1. Basic webpage Configuration:
Modify the main configuration file
# Vi/etc/httpd/CONF/httpd. conf
DocumentRoot "/var/www/html" // This row defines the path of the basic webpage, which can be customized.
Directoryindex AA index.html. var // This row defines the default homepage name. The homepage name can also be customized, and the priority of the homepage name is determined according to the order.
# Service httpd restart // start the HTTPd service
2. Personal Homepage (Www.sina.com/us1;Http: // 192.168.1.111/US1)
Modify the main configuration file
# Vi/etc/httpd/CONF/httpd. conf
# Userdir disable // This row determines whether to disable the personal homepage function. By default, the personal homepage function is disabled. If this row is disabled, the personal homepage function is enabled;
Userdir public_html // This row defines the directory name or file name of the personal homepage. The directory name or file name must be created in the user's home directory. It is disabled by default and must be enabled.
# Chmod 755 ~ US * // access the user's home directory
# Cd ~ US1 // create the public_html directory in the US1 directory and create the homepage File
# Mkdir public_html
# Vi index.html
// Create the public_html file in the us2.
# Cd ~ Us2
# Vi public_html
// Access method:
Http: // 192.168.1.111 /~ US1
Http: // 192.168.1.111 /~ Us2
// Method for canceling the Tilde: (create a soft link under the Basic webpage path)
# Cd/var/www/html
# Ln-S/home/US1/public_html US1
# Ln-S/home/us2/public_html us2
// Access method:
Http: // 192.168.1.111/US1
Personal Homepage of Apache open system users
The lab environment isCentos5.1 & rhel5The main reason is that many books on this knowledge point are incorrect in actual learning, and the Linux Tutorial we are studying is also wrong. Therefore, the steps are as follows:Fuqin liquor cooking
(1) The solution for SELinux error reporting is as follows:
Restorecon-r-V/home/Manager (Note: manager is a user of our system)
Or restorcon-r/home
2) by default, Apache disables the personal homepage function. To enable the personal homepage function, you need to set the following:
<Ifmodules mod_userdir.c>
# Userdir disable
Enable the personal homepage Function
Userdir public_html
Specify the document root directory name public_html on the personal homepage
</Ifmodules>
3) grant the directory permission for the spear Experiment
# Mkdir-P/home/manager/public_html
Create the index.html file in this directory.
# Chmod-r 755/home/Manager
Lab permission, which must be strictly controlled in a real work or production environment. The permission is not defined here./home/manager/public_html directory permission
Test: Access http: // 192.168.1.102 /~ Manager/is equivalent to accessing the file/home/manager/public_html/index.html in site 192.168.1.102, that is, the personal homepage of manager.
3. VM Configuration
A virtual host is a server with the same IP address and port. It can display different webpage content of different domain names;
The method is to direct different domain names to webpages in different directories. For example:
Www.sina.com; www.163.net; www.china.cn
You must first create multiple domain names and configure DNS;
// Modify the master configuration file and create a VM
# Vi/etc/httpd/CONF/httpd. conf
: $
// Modify it as follows:
Namevirtualhost 192.168.1.111
<Virtualhost 192.168.1.111>
DocumentRoot/Sina
Servername www.sina.com
</Virtualhost>
<Virtualhost 192.168.1.111>
DocumentRoot/www/163
Servername www.163.net
</Virtualhost>
<Virtualhost 192.168.1.111>
DocumentRoot/mnt/China
Servername www.china.cn
</Virtualhost>
// Save and exit. Restart the HTTPd service.
# Service httpd restart
4. Web page Authentication
// For basic web page authentication, modify the main configuration file:
# Vi/etc/httpd/CONF/httpd. conf
: 301 // This line indicates whether to enable the Apache web page authentication function. modify it:
AllowOverride authconfig
: 335 // This row controls whether to enable the basic web page authentication function, changed:
AllowOverride authconfig
: 414 // This row controls the name of the authentication window, which can be customized. The default is implicit file. htaccess.
Accessfilename. htaccess
// Save and exit, and create the. htaccess file under the webpage path for authentication. Now you need to create a file under the/var/www/html basic webpage path. htaccess
# Cd/var/www/html
# Vi. htaccess
// The content of the webpage authentication file is as follows:
Authname "Login Name" // defines the name of the Authentication Window
Authtype basic // define the Authentication Window Type, basic: Basic; Digest: Abstract
Authuserfile/home/APA. pwd // define the authenticated user password file and Path
Require valid-user // indicates that all users in the user password file can verify
# Require user aa bb // indicates that AA and BB in the user password file can be verified. This line and the previous line cannot be defined at the same time;
// Generate a user password file and open its access permission
# Cd/home
# Htpasswd-c apa. pwd AA
# Chmod 644 APA. pwd
// Start the HTTPd service and Test
# Service httpd restart