当前位置: 首页 > news >正文

httpd

http背景

超文本传输协议(HypeText  Transfer Protocol)互联网上应用最广泛的网络协议。1960年美国人Ted Nelson构思的一种通过计算机处理文本信息的方法,称为'超文本',这成为HTTP超文本传输协议标准架构的发展根基。

技术架构

HTTP是一个客户端和服务器端请求和应答的标准(TCP),通常,由HTTP客户端发起一个请求,建立一个到服务器指定端口(默认是80端口)的TCP连接。HTTP服务器则在那个端口监听客户端发送过来的请求。一旦收到请求,服务器(向客户端)发回一个状态,消息可能是请求的文件、错误消息,或其他信息。

软件包

http   服务端口: 80/tcp(http)
https   服务端口: 443/tcp(https,http+ssl)

配置文件

'使用rpm包安装的httpd程序环境'
/etc/httpd/conf/httpd.conf         '主配置文件'
/etc/httpd/conf.d/*.conf             '辅助配置文件'
/etc/httpd/conf.d/welcome.conf      '默认测试页面'
    /var/log/httpd/access.log               '访问日志'              
            /var/log/httpd/error_log                  '错误日志'
/var/www/html/                  '站点文档目录'
/usr/lib64/httpd/modules/     '模块文件路径'
/etc/httpd/conf.modules.d/*.conf   '模块配置文件'
mpm:以DSO机制提供,配置文件为/etc/httpd/conf.modules.d/00-mpm.conf

编译安装httpd生成的配置文件

/usr/local/apache/logs     '日志文件'
/etc/httpd24/httpd.conf   '主配置文件'
/usr/local/apache/htdocs  '站点文档目录'
'启动服务可以使用绝对路径与相对路径'
绝对路径:
[root@yaoxiaorong apache]# /usr/local/apache/bin/httpd 
httpd (pid 56281) already running
相对路径:
[root@yaoxiaorong apache]# cd /usr/local/apache/bin/
[root@yaoxiaorong bin]# ./apachectl 
httpd (pid 56281) already running

如果需要解析动态php程序,则需要安装php

'安装PHP'
[root@yaoxiaorong ~]# yum install -y php
'如果作为Apache的模块运行,并生成对应配置文件'
[root@yaoxiaorong ~]# ll /etc/httpd/modules/libphp5.so 
-rwxr-xr-x. 1 root root 4588376 Apr 13 03:04 /etc/httpd/modules/libphp5.so
[root@yaoxiaorong ~]# ll /etc/httpd/conf.d/php.conf 
-rw-r--r--. 1 root root 691 Apr 13 03:04 /etc/httpd/conf.d/php.conf
重启Apache加载PHP
[root@yaoxiaorong ~]# systemctl restart httpd
'编写php状态页面'
[root@yaoxiaorong ~]# cat >> /var/www/html/info.php <<EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@yaoxiaorong html]# systemctl restart httpd
[root@yaoxiaorong html]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128      *:80                   *:*                  
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      100    127.0.0.1:25                   *:*                  
LISTEN      0      128     :::22                  :::*                  
LISTEN      0      100    ::1:25                  :::*  
测试访问php状态页面,输入自己的IP,后面在加info.php,在操作这些步骤之前,一定要关防火墙和selinux。

如图:
httpd

编译安装httpd-2.4

'准备环境,将防火墙和selinux'
[root@yaoxiaorong ~]# setenforce 0
[root@yaoxiaorong ~]# systemctl stop firewalld
'安装开发环境'
[root@yaoxiaorong ~]# yum groups mark install "Development Tools"
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Determining fastest mirrors
 * base: mirrors.nwsuaf.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Marked install: Development Tools
[root@yaoxiaorong ~]# yum grouplist
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: mirrors.nwsuaf.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Installed Groups:
   Development Tools   '开发工具'
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
'创建apache组和用户apache'
[root@yaoxiaorong ~]# groupadd -r apache
[root@yaoxiaorong ~]# useradd -M -s /sbin/nologin -g apache apache
[root@yaoxiaorong ~]# id apache
uid=1000(apache) gid=996(apache) groups=996(apache)
'安装相关的软件包'
[root@yaoxiaorong ~]# yum -y install openssl-devel pcre-devel expat-devel libtool

·下载并安装apr-1.4和apr-util-1.4+

'下载wget'
[root@yaoxiaorong src]# yum -y install  wget
[root@yaoxiaorong ~]# cd /usr/src/
[root@yaoxiaorong src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
[root@yaoxiaorong src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
'解压下载安装apr-1.4和apr-util-1.4+的压缩包
[root@yaoxiaorong src]# tar xf apr-1.6.3.tar.bz2 
[root@yaoxiaorong src]# tar xf apr-util-1.6.1.tar.bz2 
[root@yaoxiaorong src]# ls
apr-1.6.3          apr-util-1.6.1          debug
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  kernels
'进入apr-1.6.3将修改configure配置文件'
[root@yaoxiaorong apr-1.6.3]# cd apr-1.6.3/
[root@yaoxiaorong apr-1.6.3]# vim configure
  cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    #$RM "$cfgfile"      //将此行加入注释,或者删除此行
'指定编译参数,使用./configure --help 命令查看可以使用的选项,一般常用的有  --prefix=PREFIX这个选项的意思是定义软件包安装到哪里'
[root@yaoxiaorong apr-1.6.3]# ./configure --prefix=/usr/local/apr
'编译并安装'
[root@yaoxiaorong apr-1.6.3]# make -j 2 && make install
[root@yaoxiaorong apr-1.6.3]# cd /usr/src/apr-util-1.6.1/
[root@yaoxiaorong apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@yaoxiaorong apr-util-1.6.1]# make -j 2 && make install

编译安装httpd

[root@yaoxiaorong apr-util-1.6.1]#  wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
[root@yaoxiaorong apr-util-1.6.1]# mv httpd-2.4.34.tar.bz2 /root
[root@yaoxiaorong apr-util-1.6.1]# cd
[root@yaoxiaorong ~]# ls
anaconda-ks.cfg  httpd-2.4.34.tar.bz2
[root@yaoxiaorong ~]# tar xf httpd-2.4.34.tar.bz2 
anaconda-ks.cfg  httpd-2.4.34  httpd-2.4.34.tar.bz2
[root@yaoxiaorong ~]# cd httpd-2.4.34/
[root@yaoxiaorong httpd-2.4.34]#  ./configure --prefix=/usr/local/apache \    '配置文件在的绝对路径'
> --sysconfdir=/etc/httpd24 \  
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
[root@yaoxiaorong httpd-2.4.34]# make && make install

将虚拟主机改成相同IP相同端口不同域名

[root@yaoxiaorong httpd-2.4.34]# vim /etc/httpd24/httpd.conf
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80   //取消此行前面的#号
在/etc/httpd24/httpd.conf最后一行添加以下内容:
#virtual host 1
<VirtualHost 192.168.228.20:80>
        ServerName www.yaoxiaorong.com
        DocumentRoot "/usr/local/apache/htdocs/yaoxiaorong"
        ErrorLog "logs/yaoxiaorong/error_log"
        CustomLog "logs/yaoxiaorong/access_log" combined
        <Directory /usr/local/apache/htdocs/yaoxiaorong
          <RequireAll>
          Require all granted
          Require not ip 192.168.1
          </RequireAll>
        </Directory>
</virtualHost>

/# virtual host 2     (前面的/不需要添加)
<VirtualHost 192.168.228.20:80>
        ServerName blog.yxr.com
        DocumentRoot "/usr/local/apache/htdocs/yxr"
        ErrorLog "logs/yxr/error_log"
        CustomLog "logs/yxr/access_log" combined
        <Directory /usr/local/apache/htdocs/yxr>
        <RequireAll>
          Require all granted
        </RequireAll>
       </Directory>
</VirtualHost>
'启动httpd服务,并查看80端口是否启动起来'
[root@yaoxiaorong httpd-2.4.34]# /usr/local/apache/bin/httpd
[root@yaoxiaorong httpd-2.4.34]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    :::80                 :::*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*    

创建网页目录

[root@yaoxiaorong apache]# cd /usr/local/apache/htdocs/
[root@yaoxiaorong htdocs]# ls
index.html
[root@yaoxiaorong htdocs]# mkdir yaoxiaorong
[root@yaoxiaorong htdocs]# ls
index.html  yaoxiaorong
[root@yaoxiaorong htdocs]# mkdir yxr

创建网页

[root@yaoxiaorong htdocs]# pwd
/usr/local/apache/htdocs
[root@yaoxiaorong htdocs]# echo 'hello yaoxiaorong' > yaoxiaorong/index.html
[root@yaoxiaorong htdocs]# echo 'hello yxr' > yxr/index.html

修改网页目录修改属主属组

[root@yaoxiaorong htdocs]# chown -R apache.apache yaoxiaorong
[root@yaoxiaorong htdocs]# chown -R apache.apache yxr
[root@yaoxiaorong htdocs]# ll
total 4
-rw-r--r--. 1 root   root   45 Jun 12  2007 index.html
drwxr-xr-x. 2 apache apache 24 Aug  9 17:44 yaoxiaorong
drwxr-xr-x. 2 apache apache 24 Aug  9 17:44 yxr

创建相应网页的日志目录

[root@yaoxiaorong apache]# cd logs
[root@yaoxiaorong logs]# mkdir yaoxiaorong
[root@yaoxiaorong logs]# mkdir yxr
[root@yaoxiaorong logs]# chown -R apache.apache /usr/local/apache/logs/

重新启动服务并查看是否有80端口

[root@yaoxiaorong logs]# pkill  httpd
[root@yaoxiaorong logs]# /usr/local/apache/bin/httpd
root@yaoxiaorong logs]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    :::80                 :::*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*                  

在真实主机上验证,修改C:\Windows\System32\drivers\etc配置文件

'最后一行添加以下两行'
192.168.228.20  www.yaoxiaorong.com
192.168.228.20  blog.yxr.com

在浏览器上输入www.yaoxiaorong.com测试,看能否访问

转载于:https://blog.51cto.com/13835001/2156954

相关文章:

  • 游北国风光,忆南国之乡
  • IDEA 2018创建ssm工程 运行时出现500错误
  • 微软把UWP定位成业务线应用程序开发平台
  • CentOS 7使用dnf安装Memcached以及启动、停止、开机启动等设置
  • EventListener原理
  • 数据库设计,表与表的关系,一对一。One-To-One(1)
  • 对Emlog 6.0 Beta的完整代码审计过程
  • 学习微服务的路由网关zuul——路由转发和过滤器
  • 找一份好的前端工作,起点很重要
  • Docker镜像创建及建立私有仓库
  • RichTextBox简单扩展
  • 深入剖析Retrofit系列(一)来自官方的Retrofit开发手册(中英互译)
  • java编程——高并发大容量NoSQL解决方案探索
  • Android 模拟器下载、编译及调试
  • [译]常见网页设计错误一览
  • 345-反转字符串中的元音字母
  • android图片蒙层
  • ES6系统学习----从Apollo Client看解构赋值
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • JavaScript设计模式之工厂模式
  • Java的Interrupt与线程中断
  • java正则表式的使用
  • Joomla 2.x, 3.x useful code cheatsheet
  • Laravel核心解读--Facades
  • Nacos系列:Nacos的Java SDK使用
  • QQ浏览器x5内核的兼容性问题
  • React-flux杂记
  • select2 取值 遍历 设置默认值
  • Spring Boot快速入门(一):Hello Spring Boot
  • Terraform入门 - 3. 变更基础设施
  • 闭包,sync使用细节
  • 聊聊spring cloud的LoadBalancerAutoConfiguration
  • 数据仓库的几种建模方法
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • ​ 无限可能性的探索:Amazon Lightsail轻量应用服务器引领数字化时代创新发展
  • ​​​​​​​Installing ROS on the Raspberry Pi
  • #includecmath
  • (Matalb时序预测)WOA-BP鲸鱼算法优化BP神经网络的多维时序回归预测
  • (笔试题)合法字符串
  • (附源码)php投票系统 毕业设计 121500
  • (附源码)springboot美食分享系统 毕业设计 612231
  • (理论篇)httpmoudle和httphandler一览
  • (强烈推荐)移动端音视频从零到上手(上)
  • (学习日记)2024.01.09
  • (一)SpringBoot3---尚硅谷总结
  • (原)本想说脏话,奈何已放下
  • (原)记一次CentOS7 磁盘空间大小异常的解决过程
  • (转)【Hibernate总结系列】使用举例
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • (转)Scala的“=”符号简介
  • .NET CORE 2.0发布后没有 VIEWS视图页面文件
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .net 程序 换成 java,NET程序员如何转行为J2EE之java基础上(9)
  • @ConditionalOnProperty注解使用说明
  • @for /l %i in (1,1,10) do md %i 批处理自动建立目录