1 building a Test Web server
Case:
Department built a Web server, the use of IP address and port for 192.168.10.34:80, home using index.html
File. The Administrator e-mail address is [email protected], the encoding type of the Web page is UTF-8, all the site resources are stored in the/var/www/html directory, and the Apache configuration file root directory is set to/ETC/HTTPD directory.
[[Email protected] ~] #yum-yinstall httpd
[[Email protected] ~] #vim/etc/httpd/conf/httpd.conf
To modify configuration file related parameters:
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf #以下参数需要我们掌握
ServerRoot "/ETC/HTTPD" #apache配置文件的根目录
Timeout #超时时间, number of seconds before receiving and sending
136 Listen #监听的端口
262 ServerAdmin [email protected] #设置管理员, e-mail address
277 ServerName 192.168.1.163:80 #服务器主机名.
293 DocumentRoot "/var/www/html" #网站页面根目录
Options Indexes followsymlinks #当一个目录没有默认首页时, allowing this directory list to be displayed
Disable Apache from displaying a list of directory structures, just remove the Indexes in Option
403 directoryindex index.html index.html.var# Specify default home page
Coding:
Adddefaultcharset UTF-8 # Setting the default encoding for the server is: UTF-8
2 uncheck the Apache default Welcome page:
[Email protected] ~]# vim/etc/httpd/conf.d/welcome.conf
#
# This configuration fileenables the default "Welcome"
# page If there is NoDefault index page present for
# The root URL. To disable the Welcome page, comment
# Out of all the linesbelow.
#
#<locationmatch "^/+$" > #把红色内容进行注释
# options-indexes
# ErrorDocument 403/error/noindex.html
#</locationmatch>
Restart:
[[Email protected]~]# service httpd restart
Create the home page file:
[[email protected] ~]# echo ' Welcome to www.xuegod.cn ' >/var/www/html/index.html
3 using RPM to build the lamp environment
LAMP = Linux+apache+mysql Database +php
[email protected] ~]# yum install httpd mysql-server php php-mysql
Test database:
[[Email protected] ~]# service mysqld start
Starting mysqld: [OK]
[Email protected] ~]# chkconfig mysqld on
[[email protected] ~]# MySQL
mysql> show databases;
Mysql> exit;
Bye
[Email protected] ~]# cd/var/www/html/
[Email protected] html]# vim index.php
<?php
Phpinfo ();
?>
To restart the Apache service:
[Email protected] html]# service httpd restart
stopping httpd: [OK]
Starting httpd: [OK]
MaxClients #设置客户端最大连接数为 256
4 Modify the Web site root directory and corresponding parameters, set access rights
Set the document directory to/var/www/html/bbs
Directory and Access control:
<directory "/var/www/html/bbs" > #子目录会继承这个目录的属性
Options followsymlinks #Options: Indexes: Directory Browse #Followsymlinks: can be connected
Allowoverridenone #不允许任何Override
Orderallow,deny
Allow FROM192.168.1.0/24 #从哪里来的允许
Deny from 192.168.1.0/24 #从哪里来的拒绝
Allow from. baidu.com
#Allow, Deny is read, and if there is a conflict and is not stated, follow the one that follows the order option comma.
Who writes to the back, who has a high priority.
</Directory>
Configuring the Restart Apache Service
If the error is checked, is the directory created?
Test:
Service httpd Restart #拒绝
5 Use the alias feature to refer to a path other than the root directory of the Web site
Add the/usr/local/phpmyadmin directory through the virtual directory feature to the Web site root directory. When you access http://192.168.1.63/phpmyadmin/, you can access the contents of the directory/usr/local/phpmyadmin.
Note: Apache aliases are also called virtual directories
Grammar:
Alias URL Path Physical path
Creating test catalogs and data
[Email protected] ~]# mkdir/usr/local/phpmyadmin
[Email protected] ~]# cp-r/boot/grub//usr/local/phpmyadmin/
[Email protected] ~]# echo "Test1" >/usr/local/phpmyadmin/a.html
Modifying a configuration file
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
Alias/phpmyadmin "/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
Note: alias/phpmyadmin/"/usr/local/phpmyadmin/" #/phpmyadmin/can be arbitrarily up. For example, change/phpmyadmin/to/php/then access the link: http://192.168.1.63/php/
Access http://192.168.1.63/phpmyadmin/suppresses directory listing when no default home page is present in a directory
To modify a configuration file:
[[email protected] conf]# vim/etc/httpd/conf/httpd.conf # Modify Red tag content
alias/phpmyadmin/"/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options-indexes followsymlinks #在Indexes Front plus-minus sign, this directory does not have the default home page, the directory is forbidden to display
Allowoverridenone
Orderdeny,allow
Allow from all
</Directory>
6 Open Soft link feature
Directly referencing content outside the Web site's root directory via soft links
[Email protected] ~]# MKDIR/WEB2
[Email protected] ~]# echo test1 >/web2/a.html
[Email protected] ~]# ln-s/web2//var/www/html/web2
[Email protected] ~]# rm-rf/var/www/html/index.html
[Email protected] ~]# rm-rf/var/www/html/index.php
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
[Email protected] ~]# service httpd restart
stopping httpd: [OK]
Starting httpd: [OK]
7 The/usr/local/phpmyadmin/directory under the website is protected by the user authentication method. Set the/usr/local/phpmyadmin/directory to be accessed only by user name password.
Method One:
alias/phpmyadmin/"/usr/local/phpmyadmin/"
<directory "/usr/local/phpmyadmin/" >
Options Indexesfollowsymlinks
Allowoverridenone
Orderdeny,allow
Allow from all
AuthType Basic #基本认证
AuthName "MySQL admin Software"
Authuserfile/etc/httpd/conf/passwd.secret #密文配置文件路径
#require Usertom
#require Usertom Bob
Require Valid-user #有效用户
</Directory>
Restart Apache Access http://192.168.1.63/phpmyadmin authentication
Generate an authentication account and password
[[Email protected] ~] #htpasswd-cm/etc/httpd/conf/passwd.secret Man
New Password:
Re-type New Password:
Adding Password for user mans
Verify:
Method Two:
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
<directory "/usr/local/phpmyadmin/" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
AllowOverride authconfig
</Directory>
# allowoverride Authconfig line indicates that user authentication is allowed for files in the/usr/local/phpmyadmin/directory.
[Email protected] ~]# vim/usr/local/phpmyadmin/.htaccess
AuthType Basic
AuthName "MySQL admin software by. htaccess"
Authuserfile/etc/httpd/conf/passwd.secret
#require User Tom
Require Valid-user
8 Configure Apache Virtual host to run multiple websites on a single server
Apache Virtual host implementations are available in three ways:
1. Through different IP addresses
2, through the different domain name
3, through a different port number
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
Change:
#NameVirtualHost *:80
For:
Namevirtualhost*:80
8.1 Resolving different domain names with different IP addresses
Add IP to the server (another domain name resolution)
[Email protected] ~]# ifconfigeth0:1 192.168.1.65
[Email protected] ~]# Mkdir/var/www/html/bbs
[Email protected] ~]# echo "bbs.xuegod.cn" >/var/www/html/bbs/index.html
[Email protected] ~]# echo "www.xuegod.cn" >/var/www/html/index.html
Modify Httpd.conf
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
<VirtualHost192.168.10.63:80>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_logcommon
</VirtualHost>
<virtualhost 192.168.10.65:80>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_logcommon
</VirtualHost>
Restart Service
Service httpd Restart
Test:
8.2 Configuring a virtual host with a different domain name
#vim httpd.conf
Namevirtualhost *:80
<VirtualHostwww.xuegod63.cn>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_logcommon
</VirtualHost>
<VirtualHostbbs.xuegod63.cn>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_logcommon
</VirtualHost>
Restart Service
Service httpd Restart
Modify the computer Hosts file C:\Windows\System32\drivers\etc\hosts for parsing:
192.168.10.34 www.xuegod63.cn
192.168.10.34 bbs.xuegod63.cn
Test:
8.3 Configuring a virtual host with different ports
[Email protected] conf]# vim/etc/httpd/conf/httpd.conf
Change:
Listen 80
For:
Listen 80
Listen 81
#更改为你要添加的端口
Create 2 more Virtual hosts
<virtualhost *:80>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_logcommon
</VirtualHost>
<virtualhost *:81>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_logcommon
</VirtualHost>
Restart Service
Service httpd Restart
Verify:
Http://192.168.10.34:80
http://192.168.10.34:81
2-19-Build a Web site using Apache