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.d/*.conf
3.apache的默认发布目录
/var/www/html
4.apache的默认端口
80
apache的基本配置
1.修改默认发布文件
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos.html index.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"
Require all granted
systemctl restart httpd
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
restorecon RvvF /westos
3.apache的访问控制
vim /etc/httpd/conf/httpd.conf
Order Allow,Deny
Allow from All
Deny from 172.25.254.118
Order Deny,Allow
Allow from 172.25.254.118
Deny from All
4.设定用户的访问
htpasswd -m /etc/httpd/accessuser admin
vim /etc/httpd/conf/httpd.conf
AuthUserfile /etc/httpd/accessuser #用户认证文件
AuthName "Please input your name and password !!" #用户认证提示信息
AuthType basic #认证类型
Require valid-user #认证用户,认证文件中所有用户都可以通过
4.apache语言支持
php html cgi
html语言默认支持
php语言
yum install php -y
cd /var/www/html
vim index.php
phpinfo();
?>
systemctl restart httpd
测试 :访问172.25.254.118/index.php
cgi语言
mkdir /var/www/html/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-scripts .cgi
要给index.cgi文件加可执行权限,selinux不再enforcing状态
systemctl restart httpd
apache的虚拟主机
1.定义
可以让我们的一台apache服务器在被访问不同域名的时候显示不同的主页
2.建立测试页
mkdir /var/www/virtual
cd /var/www
mkdir virtual/money.westos.com/html -p
mkdir virtual/news.westos.com/html -p
echo "money.westos.com's page" >virtual/money.westos.com/html/index.html
echo "news.westos.com's page" >virtual/news.westos.com/html/index.html
3.配置
vim /etc/httpd/conf.d/default.conf #未指定域名的访问都访问default
DocumentRoot "/var/www/html" #虚拟主机默认发布目录
Customlog "logs/default.log" combined #虚拟主机日志
vim /etc/httpd.conf.d/news.conf #指定域名news.westos.com的访问到指定默认发布目录中
ServerName "news.westos.com"
DocumentRoot "/var/www/virtual/news.westos.com/html"
Customlog "logs/news.log" combined
Require all granted
cp /etc/httpd/conf.d/news /etc/httpd/conf.d/money
vim /etc/httpd/conf.d/money
:%s/news/money/g
4.测试
在浏览器所在的主机中
vim /etc/hosts
172.25.254.118 www.westos.com news.westos.com money.westos.com