1、安装apache
dnf install httpd.x86_64 -y
systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
2、更改apache主配置文件
端口:
semanage port -l | grep httpd ##查看端口列表
vim /etc/httpd/conf/httpd.conf
---Listen 8080
netstat -antlupe | grep httpd ##查看apache端口
默认发文件:
vim /etc/httpd/conf/httpd.conf
171----DirectoryIndex westos.html index.html
systemctl restart httpd
默认发目录:
mkdir /westosdir;
vim /etc/httpd/conf/httpd.conf ##更改
---DocumentRoot "/westosdir"
---<Directory "/westosdir">
--- Require all granted
---</Directory>
systemctl restart httpd
vim /westosdir/index.html ##建立默认发文件
semanage fcontext -a -t httpd_sys_content_t '/westosdir(/.*)?' ##更改发目录安全上下文
restorecon -RF /westosdir/ ##立刻生效
3、用用户密码限制访问
cd /etc/httpd/
htpasswd -cm .westospasswd user4 ##建立名单
htpasswd -m .westospasswd user5
cat .westospasswd
mkdir /var/www/html/westos ##建要访问的目录
vim /etc/httpd/conf/httpd.conf
---<Directory "/var/www/html/westos">
AuthUserFile /etc/httpd/.westospasswd
AuthName "Please input username and password"
AuthType basic
Require user user4 ##user4可以用密码访问
# Require valid-user ##名单中的用户都可以用密码访问
---</Directory>
systemctl restart httpd
4、用id限制访问
vim /etc/httpd/conf/httpd.conf
----<Directory "/var/www/html/westos">
Order Allow,Deny ##Allow>Deny
Allow from all ##所有都允许访问
Deny from 172.25.254.244 ##244不能访问
----</Directory>
systemctl restart httpd
5.Apache的虚拟主机
mkdir -p /var/www/westos.com/{news,wenku}
echo wenku's page >/var/www/westos.com/wenku/index.html
echo news's page > /var/www/westos.com/news/index.html
echo default's page > /var/www/html/index.html
vim /etc/httpd/conf.d/Vhosts.conf
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName wenku.westos.com
DocumentRoot "/var/www/westos.com/wenku"
CustomLog logs/wenku.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot "/var/www/westos.com/news"
CustomLog logs/news.log combined
</VirtualHost>
测试:
在浏览器所在主机中
vim /etc/hosts
172.25.254.150 www.westos.com wenku.westos.ocm news.westos.com
firefox http://www.westos.com
firefox http://wenku.westos.com
firefox http://news.westos.com
6.Apache的语言支持
#php#
vim /var/www/html/index.php
<?php
phpinfo();
?>
dnf install php -y
systemctl restart httpd
firefox http://172.25.254.150/index.php
#cgi#
cd /var/www/html
ls
mkdir cgi
cd cgi
vim index.cgi
(#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
)
chmod +x index.cgi
vim /etc/httpd/conf.d/vhosts.conf
<Directory "/var/www/html/cgi">(要允许对用户目录中以.cgi结尾的任何文件执行CGI程序)
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
firefox http://192.168.0.11/cgi/index.cgi
#wsgi#
书写wsgi的测试文件
mkdir wsgi
cd wsgi
ls
vim index.wsgi
vim /var/www/html/wsgi/index.wsgi
def application(env, westos):
westos('200 ok',[('Content-Type', 'text/html')])
return [b'hello westos ahhahahahah!']
dnf install python3-mod_wsgi
systemctl restart httpd
vim /etc/httpd/conf.d/vhosts.confh
<VirtualHost *:80>
ServerName wsgi.westos.com
WSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>
在真机上:
vim /etc/hosts
172.25.254.132 www.westos.com new.westos.com wsgi.westos.com(写在一行)