以下所有操作都是在Red-hat 7.0上
|####################Apache的安裝#####################|
yum install httpd -y
systemctl start httpd
systemctl stop firewalld
systemctl enable httpd
systemctl disable firewalld
|##################Apache的基本參數#################|
1.Apache的默認文件
index.html
2.Apache的配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/*.conf
3.Apache的默認發佈目錄
/var/www/html
4.Apache的默認端口
80
|##################Apache的基本配置#################|
1.修改默認發佈文件
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos.html
2.修改默認發佈目錄
** ##當selinux是disabled狀態
vim /etc/httpd/conf/httpd.conf
**120 DocumentRoot “ /westos/www/test”
* Require all granted*
systemctl restart httpd
* ##當selinux是Enforcing狀態*
vim /etc/httpd/conf/httpd.conf
120 DocumentRoot “ /westos/www/test”
systemctl restart httpd
semanage fcontext -a -t http_sys_content ‘/westos(/.*)?’ ##修改安全上下午
restorecon -RvvF /westos ##激活剛纔修改的安全上下文
|####################Apache支持的語言#####################|
1.Apache支持的語言
HTML PHP CGI
2.cgi語言
mkdir /var/www/html/cgi ##建議cgi的默認目錄
vim index.cgi
#!/usr/bin/perl
**print “Content-type”:text/html\n\n”;
**print date
;
**vim /etc/httpd/conf/httpd.conf
* Options +ExecCGI*
* AddHandler cgi-script .cgi*
* systemctl restart httpd*
**(提示:做這個實驗時,一定將selinux不要改成Enforing)
|##################Apache的訪問控制###################|
1.設定ip訪問
**vim /etc/httpd/conf/httpd.conf
* Order Allow,Deny ##這裏別亂敲空格*
** Allow from All
** Deny from 172.25.254.250
**vim /etc/httpd/conf/httpd.conf
* Order Deny,Allow ##這裏別亂敲空格*
** Allow from 172.25.254.250
** Deny from All
2.設定用戶訪問
創建認證用戶
htpasswd -cm /etc/httpd/accessuser admin ##第一次創建時是-cm,如果第二次還是-cm,就會覆蓋前面的內容
vim /etc/httpd/conf/httpd.conf
AuthUserFile /etc/httpd/accessuser ##用戶認證文件
AuthName “Please input your name and password!”##提示信息
AuthType basic ##認證類型
Require valid-user ##認證用戶,建立的都可以認證
|##################Apache的虛擬主機###################|
1.定義
可以讓我們的一臺Apache服務器在被訪問不同域名時候顯示不同的主頁
2.建議測試頁
3.配置