分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

httpd

发布时间:2023-09-06 02:09责任编辑:顾先生关键词:http
编译安装httpd-2.4

‘准备环境,将防火墙和selinux‘[root@yaoxiaorong ~]# setenforce 0[root@yaoxiaorong ~]# systemctl stop firewalld
‘安装开发环境‘[root@yaoxiaorong ~]# yum groups mark install "Development Tools"Loaded plugins: fastestmirrorRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fastThere 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.comMarked install: Development Tools[root@yaoxiaorong ~]# yum grouplistLoaded plugins: fastestmirrorRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fastLoading mirror speeds from cached hostfile * base: mirrors.nwsuaf.edu.cn * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.comAvailable 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 WorkstationInstalled 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 ManagementDone
‘创建apache组和用户apache‘[root@yaoxiaorong ~]# groupadd -r apache[root@yaoxiaorong ~]# useradd -M -s /sbin/nologin -g apache apache[root@yaoxiaorong ~]# id apacheuid=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 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]# lsapr-1.6.3 ?????????apr-util-1.6.1 ?????????debugapr-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 ~]# lsanaconda-ks.cfg ?httpd-2.4.34.tar.bz2[root@yaoxiaorong ~]# lsanaconda-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 ??//取消此行前面的#号‘启动httpd服务,并查看80端口是否启动起来‘[root@yaoxiaorong httpd-2.4.34]# /usr/local/apache/bin/httpd[root@yaoxiaorong httpd-2.4.34]# ss -antlState ?????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]# lsindex.html[root@yaoxiaorong htdocs]# mkdir yaoxiaorong[root@yaoxiaorong htdocs]# lsindex.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]# lltotal 4-rw-r--r--. 1 root ??root ??45 Jun 12 ?2007 index.htmldrwxr-xr-x. 2 apache apache 24 Aug ?9 17:44 yaoxiaorongdrwxr-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/

在配置文件的最后加入如下内容

[root@yaoxiaorong logs]# tail -25 /etc/httpd24/httpd.conf #virtual host 1 ???‘虚拟主机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# ??‘虚拟主机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>

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

[root@yaoxiaorong logs]# pkill ?httpd[root@yaoxiaorong logs]# /usr/local/apache/bin/httpdroot@yaoxiaorong logs]# ss -antlState ?????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.com192.168.228.20 ?blog.yxr.com

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

httpd

原文地址:http://blog.51cto.com/13835001/2156954

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved