apache 服务

apache 服务

TCP端口有哪些

web服务类型:IIS、Tomcat、Zeus、Nginx、Apache、Lighttpd
Apache的工作模式:prefork/ worker/Event
动态资源服务器
反向代理,静态资源服务器
tengine 阿里的
正向代理 eg:翻墙
反向代理 eg:打10086客服,
lamp:Linux(操作系统)、Apache(HTTP服务器)、MySQL(也指MariaDB,数据库软件)和PHP(有时也是指Perl或Python)的第一个字母,一般用来建立web应用平台。
lnmp:linux下使用nginx服务器,mysql数据库,php脚本的服务器环境。

netstat -antlupe ##查看打开端口
——————————————————————————————————————————————————————————————————————————

1.什么是apache

一种web服务,提供http协议访问
默认发布目录:/var/www/html/
默认访问页面:index.html 里面可以写东西,就会显示在网页
默认端口:80
默认安全上下文:http_sys_content_t
程序开启默认用户:apache
apache日志:/etc/httpd/logs/*
主配置目录:/etc/httpd/
主配置文件:/etc/httpd/conf/httpd.conf
子配置目录:/etc/httpd/conf.d
子配置文件:/etc/httpd/conf.d/*.conf

2.安装部署

网页打不开,服务没开或火墙没添加服务
帮助手册:httpd-manual.noarch

yum install httpd -y
yum install httpd-manual.noarch -y	##安装帮助手册
systemctl start httpd
systemctl enable httpd
systemctl status httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload

修改默认发布文件内容:

vim /var/www/html/index.html
<h1>hi! gg</h1>					##html语言格式

在这里插入图片描述
修改默认端口:

vim /etc/httpd/conf/httpd.conf
43	Listen 8080					##43行做修改

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload 
systemctl restart httpd

在这里插入图片描述
在这里插入图片描述
修改默认发布文件:

vim /etc/httpd/conf/httpd.conf
164     DirectoryIndex westos  index.html

vim /var/www/html/westos
hi! mm

systemctl restart httpd

在这里插入图片描述
在这里插入图片描述

修改默认发布目录:

vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/westos/html"
120 <Directory "westos">
121      Require all granted		##允许所有请求访问资源
122 </Directory> 

mkdir -p /westos/html
systemctl restart httpd

在这里插入图片描述
在这里插入图片描述

3.访问控制

3.1 指定主机访问

mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
<h1>=.=</h1>

vim /etc/httpd/conf/httpd.conf 
120 <Directory "/var/www/html/westos">
121         Order Allow,Deny			##顺序查看
122         Allow from All
123         Deny from 172.25.254.1   	##后查看的会覆盖前面的
124 </Directory>

systemctl restart httpd

在这里插入图片描述

在这里插入图片描述

3.2 指定用户访问

htpasswd -cm westosuser admin	##第一次建立要加c,第二次不用
htpasswd -m westosuser admin1

vim /etc/httpd/conf/httpd.conf       
<Directory "/var/www/html/westos">
    AuthUserFile    /etc/httpd/conf/westosuser	##加密密码的文件
    AuthType        basic						##基础认证类型
    AuthName        "password is 123"			##提示
    Require user    admin						##允许admin用户进行访问
	#Require	valid-user						##所有有效的用户可访问资源
</Directory>

cd /etc/httpd/conf/
systemctl restart httpd
当密码错误时会让重新输入

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.虚拟主机

如何让一个ip对应多个站点?

添加站点
vim /etc/hosts
172.25.254.107 www.westos.com news.westos.com music.westos.com

vim /etc/httpd/conf/httpd.conf
注释之前的设置

mkdir /var/www/virtual/news/html -p
mkdir /var/www/virtual/music/html -p		##创建俩个站点各自对应的家目录
vim /var/www/virtual/news/html/index.html
<h1>news</h1>

vim /var/www/virtual/music/html/index.html
<h1>music</h1>								##写入网页内容

写默认站点对应的解析

cd /etc/httpd/conf.d/
vim default.conf
<VirtualHost _default_:80>			##_default_:80 默认目录可以通过80端口被访问
    DocumentRoot    /var/www/html
    CustomLog       logs/default.log combined	##combined 混合型日志
</VirtualHost>

news站点的解析

vim news.conf 
<VirtualHost *:80>					##*:80 所有目录可以通过80端口被访问
    ServerName      news.westos.com
    DocumentRoot    /var/www/virtual/news/html
    CustomLog       logs/news.log combined
</VirtualHost>
<Directory "/var/www/virtual/news/html">
    Require all granted
</Directory>

music站点的解析

vim music.conf
<VirtualHost *:80>
    ServerName      music.westos.com
    DocumentRoot    /var/www/virtual/music/html
    CustomLog       logs/music.log combined
</VirtualHost>
<Directory "/var/www/virtual/music/html">
    Require all granted
</Directory>

##以上内容可以写在一起
systemctl restart httpd
curl news.westos.com
curl music.westos.com

5. php+cgi

php:

cgi:(通用网关接口)httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等。CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体

FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信较于CGI方式,FastCGI更为常用,很少有人使用CGI方式来加载动态资源。CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时

5.1 php(php)

vim /var/www/html/index.php
<?php
phpinfo();
?>
##php语言框架
yum install php -y 
systemctl restart httpd

5.2 cgi(perl)

mkdir /var/www/html/cgi
cd /var/www/html/cgi
vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
##cgi语言框架
chmod 775 index.cgi 	##赋予执行权限
./index.cgi

vim /etc/httpd/conf.d/default.conf
在下面添加:
<Directory /var/www/html>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

浏览器打开:
http://172.25.254.107/cgi/index.cgi

6.https&重定向

curl -I ##解析站点
https:443端口
301永久重定向
302临时重定向
200正常

6.1 apache的ssl

yum install mod_ssl.x86_64  -y
systemctl restart httpd.service

https://172.25.254.107/

在这里插入图片描述

6.2 制作自签名证书

yum install crypto-utils.x86_64  -y
genkey www.westos.com
注意:不发送ca(认证),录入信息可以敲字加速

vim /etc/httpd/conf.d/ssl.conf
100 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
107 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

systemctl restart httpd.service 

在这里插入图片描述

6.3 网页重写

强制重定向,端口转发

cd /etc/httpd/conf.d/
cp news.conf  login.conf
mkdir  -p /var/www/virtual/login/html
vim /var/www/virtual/login/html/idnex.html
<h1>login</h1>

vim login.conf
<VirtualHost *:443>
    ServerName      login.westos.com
    DocumentRoot    /var/www/virtual/login/html
    CustomLog       logs/login.log combined
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
    SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
<Directory "/var/www/virtual/login/html">
    Require all granted
</Directory>

<VirtualHost *:80>
    ServerName      login.westos.com
    RewriteEngine   On
    RewriteRule     ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>

^(/.*)$			##你在浏览器的输入
$1				##用户第一次输入的值
redirect=301	##转换成永久
%{HTTP_HOST}	##客户请求主机

7. wscgi(python)

支持多线程
中间键:tomcat jboss

mkdir /var/www/wscgi
cd /var/www/wscgi
wget http://172.25.254.250/RHCEPACKAGES/materials/script.wsgi
yum install mod_wsgi.x86_64 -y
vim /etc/httpd/conf.d/wsgi.conf
<VirtualHost *:80>
    ServerName  www.westoswsgi.com
    WSGIScriptAlias / /var/www/wscgi/script.wsgi
</VirtualHost>

ystemctl restart httpd

vim /etc/hosts
172.25.254.107  www.westoswsgi.com

浏览器:
www.westoswsgi.com

8. cdn缓存加速

三次加速
反向代理
squid端口:3128

8.1 正向代理

eg:翻墙
行56#允许所有,行62#建立缓存目录
两台主机,其中一台A做服务端(代理)有网络,一台B做测试无网络
目的:使B通过A上网

yum install squid.x86_64 -y
vim /etc/squid/squid.conf
56 http_access allow all
62 cache_dir ufs /var/spool/squid 100 16 256

systemctl stop firewalld.service 
systemctl restart squid

测试端:
浏览器修改代理地址:Preferences---->Advanced----->Network----->Settings

浏览器进网站

8.2 反向代理

两台主机一台配置好apache,一台A配置squid;另一台B没有apache做以下配置
目的:使B可以使用A的apache(缓存加速)
在B:安装squid,防火墙打开http、https服务

vim /etc/squid/squid.conf
cache_peer 172.25.254.132 parent 80 0 proxy-only
##proxy-only只做缓存

systemctl restart squid

在B的浏览器输入B的ip

9. 轮询调度(web集群)

目的:使一台主机A可以轮换访问两台服务器,减缓服务器压力

vim /etc/squid/squid.conf
cache_peer 172.25.254.xxx parent 80 0 proxy-only round-robin originserver name=web1 weight=3
cache_peer 172.25.254.xxx parent 80 0 proxy-only round-robin originserver name=web2
cache_peer_domain www.westos.com web1 web2		##给用户一个用来访问的站点

#weight=3表示权重,3:1
##round-robin表示轮询
##originserver web服务器的标识

要使另一台主机可以通过B访问站点,则需打开两台主机中的火墙的http和https服务

10. 论坛搭建

搭建http服务
首先需要一个论坛的源,将压缩包解压到/var/www/html/下
根据说明内容设置权限

安装php服务
安装数据库,修改密码、安全设定
写http的指向文件
vim /etc/httpd/conf.d/default.conf
写入指向,及域名解析

浏览器:xxx.xxx.com
进行安装,将未通过的设置更改
安装php-mysql
重启服务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值