apache
web服务 开源---开放源代码 ---免费
apache 两种
yum安装 rpm
client 192.168.2.10 自带火狐浏览器 firefox
web 192.168.2.20
web:
[root@localhost ~]# yum -y install httpd
需要把网页 放到站点跟目录下面 用户就可以直接访问
[root@localhost ~]# cd /var/www/html/ #默认的站点根目录
index.html apache的配置当中 默认只识别这个网页
[root@localhost html]# echo 111111 > index.html
[root@localhost html]# ls
index.html
[root@localhost html]# cat index.html
111111
[root@localhost html]# systemctl start httpd
[root@localhost html]# netstat -anput | grep httpd
tcp6 0 0 :::80 :::* LISTEN 4665/httpd
[root@localhost html]# firewall-cmd --add-port=80/tcp --permanent
success
[root@localhost html]# firewall-cmd --reload
success
client
[root@localhost ~]# firefox http://192.168.2.20
11111111
通过域名访问:
1.可以搭建dns----作业 源码安装httpd it works
2./etc/hosts
192.168.2.20 www.aaa.com web的IP
[root@localhost ~]# firefox http://www.aaa.com
对于web服务而言 更改页面是不需要重启服务的
[root@localhost html]# cat index.html
111111
[root@localhost html]# echo 2222222 > index.html
apache
yum 程序文件在不同目录下
站点根目录 /var/www/html
配置文件 --改变 ---重启服务
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
日志文件 cd /var/log/httpd/
access_log 访问日志
error_log 配置文件中有问题
[root@localhost httpd]# cat access_log
192.168.2.10 - - [13/Oct/2021:14:41:18 +0800] "GET / HTTP/1.1" 200 8
client也可以使用curl访问
[root@localhost ~]# curl www.aaa.com
2222222
服务端也可以作为client
[root@localhost httpd]# curl 192.168.2.20
2222222
[root@localhost httpd]# curl 127.0.0.1
2222222
拒绝连接 服务没有开启
没有主机路由 防火墙/ping不通
源码安装 tar.gz 编译
源码安装 apache
1.自己可以指定目录
2.配置安装比较麻烦
公司使用源码安装比较多
yum和源码安装会冲突
client 2.10
web apache 2.20
apache
[root@localhost httpd]# systemctl stop httpd
[root@localhost httpd]# cd
[root@localhost ~]# yum -y remove httpd
源码安装apache
1.安装依赖关系
[root@localhost ~]# yum -y install gcc* zlib zlib-devel pcre pcre-devel openssl openssl-devel
zlib 关于压缩的依赖库文件
pcre 地址重写的依赖文件
openssl ssl的依赖文件
httpd 2版本之上 apr依赖关系 指定apr的安装目录
[root@localhost ~]# tar -zxf apr-1.4.5.tar.gz
[root@localhost ~]# cd apr-1.4.5/
[root@localhost apr-1.4.5]# ./configure --prefix=/usr/local/apr && make && make install
[root@localhost ~]# tar -zxf apr-util-1.3.12.tar.gz
[root@localhost ~]# cd apr-util-1.3.12/
[root@localhost apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
[root@localhost apr-util-1.3.12]# cd
[root@localhost ~]# tar -zxf httpd-2.4.25.tar.gz
[root@localhost ~]# cd httpd-2.4.25/
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/httpd --with-zlib --with-pcre --enable-so --enable-ssl --with-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=worker --enable-modules=most && make && make install
--prefix=/usr/local/httpd #指定httpd的安装目录
--with-zlib #指定httpd的依赖包zlib 可以实现对httpd的数据压缩传输
--with-pcre #指定httpd的依赖pcre 可以实现httpd的正则表达式
--enable-so #支持动态加载so模块
--enable-ssl #支持ssl协议 实现https的部署
--with-rewrite #支持url的地址重写
--with-apr=/usr/local/apr #http的依赖apr
--with-apr-util=/usr/local/apr-util #http依赖apr-util
--with-mpm=worker #支持httpd的工作模式worker
--enable-modules=most #指定httpd安装时加载多个工作模式
[root@localhost ~]# cd /usr/local/httpd/
[root@localhost httpd]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
源码安装站点目录
[root@localhost httpd]# cd /usr/local/httpd/
[root@localhost httpd]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
#站点目录
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
index.html
#自带的页面
[root@localhost htdocs]# cat index.html
<html><body><h1>It works!</h1></body></html>