Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。
LAMP框架指的是:
LAMP=Linux+Apache+MySql+PhP
#######apache服务的安装######
yum install httpd -y ##安装服务
yum install httpd-manual.noarch ##安装帮助文档172.25.254.1/manual ##用浏览器可以查看到(也可以在网上搜索)
####http服务的基础启动######
1.yum install httpd -y ##安装服务
2.systemctl start httpd ##开启服务
3.systemctl enable httpd ##开机自启
4.firewall-cmd --permanent --add-service=http ##关闭火墙限制
5.firewall-cmd --permanent --add-service=https
6.firewall-cmd --reload
7.vim /var/www/html/index.html ##修改默认页面
####/etc/httpd/conf/httpd.conf####
####这是httpd的主配置文件######
->修改默认端口(默认为80)
1.vim /etc/httpd/conf/httpd.conf
> Listen 8080 ##修改端口
2.firewall-cmd --permanent --add-port=8080/tcp
3.firewall-cmd --reload ##允许火墙的限制,开放8080端口
访问的时候机的在网址后面加上:80
->修改默认入口文件(默认是index.html)
1.vim /etc/httpd/conf/httpd.conf
>DirectoryIndex index.html linux.html ##需要重启服务
->修改默认目录(修改为/www/html)
1.vim /etc/httpd/conf/httpd.conf ##编辑配置文件(>修改 +添加)
> DocumentRoot "/www/html"
+ <Directory "/www">
+ Require all granted
+ </Directory>
2.semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
##注意selinux的影响
#####虚拟服务器(一个IP对应多个域名)######
##需要客户机中将多个域名对应同一个IP
->客户机简单修改
vim /etc/hosts
+ 172.25.254.113 www.linux.com www.mengran.com
##www.mengran.com是特殊域名,即登陆时要进入专用的界面
->服务器的修改
1.vim /etc/httpd/conf.d/default.conf ##新建子配置文件(非特殊域名登陆)
+ <virtualhost _default_:80>
+ documentroot /var/www/html
+ customlog "logs/default.log" combined ##日志的位置及其类型
+ </virtualhost>
+
+ <directory /var/www/html>
+ require all granted ##目录授权
+ </directory>
2.vim /etc/httpd/conf.d/mengran.conf ##新建子配置文件(特殊域名登陆)
+ <virtualhost *:80>
+ servername www.mengran.com ##说明特殊服务器
+ documentroot /var/www/MR ##这个目录以及里面的文件要自己建立
+ customlog "logs/mengran.log" combined
+ </virtualhost>
+
+ <directory /var/www/MR>
+ require all granted
+ </directory>
#####访问限制#####
1.vim /etc/httpd/conf.d/mengran.conf
+ <directory /var/www/MR/MM> ##这个目录需要自建——限制IP
+ Order deny,allow ##顺序
+ allow from 172.25.254.13
+ deny from all
+ </directory>
+
+ <directory /var/www/MR/RR> ##密码限制
+ Authuserfile /etc/httpd/conf/fileuser ##密码文件在下面建立
+ Authname "HAHAHAHA"
+ Authtype basic
+ require valid-user
+ </directory>
2.htpasswd -cm fileuser admin ##新建
3.htpasswd -m fileuser tom ##添加
#####apache中的插件(PHP,CGI)####
->PHP服务
1.yum install php -y ##安装php
2.systemctl restart httpd.service ##重启服务即可
3.vim /var/www/html/index.php
+ <?php
+ phpinfo ();
+ ?>
->CGI脚本
1.vim /var/www/html/index.cgi ##新建一个cgi脚本
+ #!/usr/bin/perl
+ print "Content-type: text/html\n\n";
+ print `date +%H:%M:%S`;
2.chmod +x index.cgi ##给与执行权限
3.vim /etc/httpd/conf.d/default.conf ##编辑默认配置文件
+ <Directory /home/*/public_html>
+ Options +ExecCGI
+ AddHandler cgi-script .cgi
+ </Directory>
3.setenforce 0 ##关掉SELinux的影响,也可以修改安全上下文
#####https的配置(建立一个https的域名)(加密传输)####
1.yum install mod_ssl.x86_64 -y ##安装https(httpd的插件)
2.yum install crypto-utils.x86_64 -y ##安装证书产生器
3.genkey $(hostname) ##生成证书,期间加密字符可能不够
4.vim /etc/httpd/conf.d/login.conf ##编辑文件(自己建立)
+ <virtualhost *:443>
+ servername login.linux.com
+ documentroot /var/www/login
+ customlog "logs/login.log" combined
+ SSLEngine on
+ SSLCertificateFile /etc/pki/tls/certs/dns-servser1.crt
+ SSLCertificateKeyFile /etc/pki/tls/private/dns-servser1.key
+ </virtualhost>
+
+ <directory /var/www/login>
+ require all granted
+ </directory>
+
+ <virtualhost *:80>
+ servername login.linux.com
+ rewriteengine on
+ RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
+ </virtualhost>
5.systemctl restart httpd.service ##重启服务