CentOS7搭建httpd服务

2023-11-13

httpd

1.httpd安装

。使用yum安装:

1.安装命令yum -y install httpd

httpd服务的主配置文件通常为httpd根目录下的conf/httpd.conf文件,通过yum安装的httpd服务的主配置路径通常如下:
/etc/httpd/conf/httpd.conf

2.vim /etc/httpd/conf/httpd.conf 配置虚拟主机

               NameVirtualHost(虚拟主机的名称)   192.......

​                   <VirtualHost(虚拟主机)  192............>

​                   DocumentRoot(文件根)   "/var/www/html/"

​                   ServerName(服务器名称)   192.........

​                  </VirtualHost>

3.进入网站目录站点 cd /var/www/html

echo "123 123 123 china " >  index.html        //生成index文件输入内容

//  启动httpd服务
[root@scl ~]# systemctl start httpd
[root@scl ~]# 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                                           :::* 

 //  关闭防火墙和selinux
 [root@scl ~]# systemctl stop firewalld

 直接修改vim /etc/selinux/config找到SELINUX=enforcing修改为SELINUX=disable
 [root@scl ~]# setenforce 0

4.在浏览器输入ip验证
在这里插入图片描述

//配置文件说明

文件/目录 对应的功能
/var/log/httpd/access.log 访问日志
/var/log/httpd/error_log 错误日志
/var/www/html/ 站点文档目录
/usr/lib64/httpd/modules/ 模块文件路径
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/conf.modules.d/*.conf 模块配置文件
/etc/httpd/conf.d/*.conf 辅助配置文件

。httpd命令

//语法:httpd [options]
//常用的options:
    -l      //查看静态编译的模块,列出核心中编译了哪些模块。 \
            //它不会列出使用LoadModule指令动态加载的模块
    -M      //输出一个已经启用的模块列表,包括静态编译在服务 \
            //器中的模块和作为DSO动态加载的模块
    -v      //显示httpd的版本,然后退出
    -V      //显示httpd和apr/apr-util的版本和编译参数,然后退出
    -X      //以调试模式运行httpd。仅启动一个工作进程,并且 \
            //服务器不与控制台脱离
    -t      //检查配置文件是否有语法错误

。curl命令

curl是基于URL语法在命令行方式下工作的文件传输工具,它支持FTP,FTPS,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE及LDAP等协议。

curl支持以下功能:

  • https认证
  • http的POST/PUT等方法
  • ftp上传
  • kerberos认证
  • http上传
  • 代理服务器
  • cookies
  • 用户名/密码认证
  • 下载文件断点续传
  • socks5代理服务器
  • 通过http代理服务器上传文件到ftp服务器
//语法:curl [options] [URL ...]
//常用的options:
    -A/--user-agent <string>    //设置用户代理发送给服务器
    -basic              //使用Http基本认证
    --tcp-nodelay       //使用TCP_NODELAY选项
    -e/--referer <URL>      //来源网址
    --cacert <file>     //CA证书(SSL)
    --compressed        //要求返回时压缩的格式
    -H/--header <line>  //自定义请求首部信息传递给服务器
    -I/--head           //只显示响应报文首部信息
    --limit-rate <rate>     //设置传输速度
    -u/--user <user[:password]>     //设置服务器的用户和密码
    -0/--http1      //使用http 1.0版本,默认使用1.1版本。这个选项是数字0而不是字母o
    -o/--output     //把输出写到文件中
    -#/--progress-bar       //进度条显示当前的传送状态
//通过curl下载文件
[root@scl ~]# curl -o myblog.html https://blog.csdn.net/whell_scl
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100 15137    0 15137    0     0  47412      0 --:--:-- --:--:-- --:--:-- 47750
[root@scl ~]# ls
myblog.html

。编译安装httpd-2.4

httpd依赖于apr-1.4以上版本,apr-util-1.4以上版本

1.安装开发环境
[root@scl ~]# yum groupinstall "Development Tools"
安装过程省略…

2.安装相关依赖包
[root@scl ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
安装过程省略…

3.下载apr-1.6.3和apr-util-1.6.1和httpd-2.4

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
[root@localhost src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
[root@localhost src]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2

[root@scl src]# ls
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.34.tar.bz2  kernels

4.解压下好的tar包

[root@scl src]# tar xf apr-1.6.3.tar.bz2 
[root@scl src]# tar xf apr-util-1.6.1.tar.bz2 
[root@scl src]# tar xf httpd-2.4.34.tar.bz2
[root@scl src]# ls
apr-1.6.3  apr-1.6.3.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.34  httpd-2.4.34.tar.bz2

5.安装

// 编译安装apr-1.6.3
[root@scl src]# cd apr-1.6.3
[root@scl apr-1.6.3]# vim configure
 # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@scl ~]# ./configure --prefix=/usr/local/apr
配置过程略。。。
[root@scl apr-1.6.3]# make && make install
编译过程略。。。

// 编译安装apr-util-1.6.1
[root@scl apr-1.6.3]# cd /usr/src/apr-util-1.6.1
[root@scl apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
配置过程略。。。
[root@scl apr-1.6.3]# make && make install
编译过程略。。。

// 编译安装httpd-1.4
[root@scl src]# cd httpd-2.4.34
[root@scl 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@scl httpd-2.4.34]# make && make install
编译过程略。。。

添加环境变量:

[root@scl ~]# echo "export PATH=/usr/local/apache/bin:$PATH" >/etc/profile.d/httpd.sh
[root@scl ~]# . /etc/profile.d/httpd.sh 
[root@scl ~]# which httpd
/usr/local/apache/bin/httpd

在浏览器输入ip验证

[root@scl ~]# /usr/local/apache/bin/apachectl start             //  启动服务
[root@scl ~]# vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80         //  将这一行前面的注释去掉
[root@scl ~]# systemctl stop firewalld    //  关闭防火墙

在这里插入图片描述

2.httpd常用配置

切换使用MPM
yum安装的情况下(编辑[root@scl ~]# /etc/httpd/conf.modules.d/00-mpm.conf文件

//NAME有三种,分别是:
    prefork
    event
    worker

编译安装的情况下:(编辑[root@scl ~]# vim /etc/httpd24/httpd.conf)

#LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so    //目前使用的
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
//  如果要用其他的请把前面的注释去掉,但是同时只能使用一个

网页目录站点位置
yum安装的默认网页目录站点(/var/www/html/)

[root@100 ~]# cd /var/www/html/
[root@100 html]# ls
 index.html

源码安装的默认网站目录站点(/usr/local/apache/htdocs/)

[root@scl ~]# cd /usr/local/apache/htdocs/
[root@scl htdocs]# ls
index.html

日志的存放位置
yum安装默认日志存放位置(cd /var/log/httpd/

[root@100 ~]# cd /var/log/httpd/
[root@100 httpd]# ls
access_log  error_log

源码安装默认日志存放位置(/usr/local/apache/logs/

[root@100 httpd]# cd /usr/local/apache/logs/
[root@100 logs]# ls
access_log  error_log  httpd.pid

。访问控制法则:

法则 功能
Require all granted 允许所有主机访问
Require all deny 拒绝所有主机访问
Require ip IPADDR 授权指定来源地址的主机访问
Require not ip IPADDR 拒绝指定来源地址的主机访问
Require host HOSTNAME 授权指定来源主机名的主机访问
Require not host HOSTNAME 拒绝指定来源主机名的主机访问
IPADDR的类型 HOSTNAME的类型
IP:192.168.1.1 DOMAIN:指定域内的所有主机
Network/mask:192.168.1.0/255.255.255.0 Net:192.168 FQDN:特定主机的全名
Network/Length:192.168.1.0/24

示例:
// 设置仅192.168.100.96这台主机能访问:

// 现在是任意主机都能访问
[root@100 ~]# curl http://192.168.100.100/index.html
<html><body><h1>It works!</h1></body></html>

[root@96 ~]# curl http://192.168.100.100/index.html
<html><body><h1>It works!</h1></body></html>

// 进入配置文件修改
<Directory /usr/local/apache/htdocs>
    <RequireAll>
        Require ip 192.168.100.100
        Require all granted
    </RequireAll>
</Directory>

// 重启服务
[root@100 ~]# apachectl restart 

//  使用192.168.100.96访问
[root@96 ~]# curl http://192.168.100.100/index.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>                            // Forbidden 禁止访问
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /index.html      //没有访问权限
on this server.<br />
</p>
</body></html>

//使用192.168.100.100访问
[root@100 ~]# curl http://192.168.100.100/index.html
<html><body><h1>It works!</h1></body></html>              //依然可以访问

3.虚拟主机:

虚拟主机有三类::

  • 相同IP不同端口
  • 不同IP相同端口
  • 相同IP相同端口不同域名

。相同ip不同端口的配置:

[root@localhost ~]# [root@100 ~]# vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80       //取消此行前面的#号

[root@localhost ~]# vim /etc/httpd24/httpd.conf 
//在配置文件的最后加上如下内容:
#NameVirtualHost              //如果是httpd2.2版本就要加上这一行如果是2.4版本就不要加
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/rutime.example.com-access_log" common
</VirtualHost>

<VirtualHost *:81>
    DocumentRoot "/usr/local/apache/htdocs/wheel"
    ServerName wheel.example.com
    ErrorLog "logs/wheel.example.com-error_log"
    CustomLog "logs/wheel.example.com-access_log" common
</VirtualHost>

//  在配置文件中修改监听的端口号
[root@localhost ~]#  vim /etc/httpd24/httpd.conf 
#
#Listen 12.34.56.78:80
Listen 80
Listen 81          // 新添加一个81端口

// 创建网站的根目录并且写入内容到index文件中
[root@100 ~]# mkdir /usr/local/apache/htdocs/runtime
[root@100 ~]# mkdir /usr/local/apache/htdocs/wheel
[root@100 ~]# apachectl -t
Syntax OK
[root@100 ~]# echo "runtime" >/usr/local/apache/htdocs/runtime/index.html
[root@100 ~]# echo "wheel" >/usr/local/apache/htdocs/wheel/index.html

[root@100 ~]# apachectl restart     //重启服务
[root@100 ~]# 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                              :::81                                           :::*                  
LISTEN      0      128                              :::22                                           :::*                  
LISTEN      0      100                             ::1:25                                           :::* 

浏览器进行验证:
输入ip192.168.100.100 //默认使用的是80端口
在这里插入图片描述
使用81端口访问:
在这里插入图片描述

。不同IP相同端口配置:

[root@localhost ~]#  vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80       //取消此行前面的#号

[root@localhost ~]#  vim /etc/httpd24/httpd.conf
//在配置文件的最后加上如下内容:
#NameVirtualHost              //如果是httpd2.2版本就要加上这一行如果是2.4版本就不要加
<VirtualHost 192.168.100.100:80>
    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/rutime.example.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.100.101:80>
    DocumentRoot "/usr/local/apache/htdocs/wheel"
    ServerName wheel.example.com
    ErrorLog "logs/wheel.example.com-error_log"
    CustomLog "logs/wheel.example.com-access_log" common
</VirtualHost>

// 创建网站的根目录并且写入内容到index文件中
[root@100 ~]# mkdir /usr/local/apache/htdocs/runtime
[root@100 ~]# mkdir /usr/local/apache/htdocs/wheel
[root@100 ~]# apachectl -t
Syntax OK
[root@100 ~]# echo "runtime" >/usr/local/apache/htdocs/runtime/index.html
[root@100 ~]# echo "wheel" >/usr/local/apache/htdocs/wheel/index.html

[root@100 ~]# apachectl restart     //重启服务
[root@100 ~]# 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                              :::81                                           :::*                  
LISTEN      0      128                              :::22                                           :::*                  
LISTEN      0      100                             ::1:25                                           :::* 

//给主机服务端再添加一个ip为192.168.100.101
[root@100 ~]# ip addr add 192.168.100.101 dev eth0
[root@100 ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:0f:a6:60 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.100/24 brd 192.168.100.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.100.101/32 scope global eth0
       valid_lft forever preferred_lft forever

// 验证:
使用192.168.100.100访问:
在这里插入图片描述
使用192.168.100.101访问;
在这里插入图片描述

。相同IP相同端口不同域名配置

[root@localhost ~]#  vim /etc/httpd24/httpd.conf
ServerName www.example.com:80       //取消此行前面的#号

[root@localhost ~]#  vim /etc/httpd24/httpd.conf
//在配置文件的最后加上如下内容:
#NameVirtualHost              //如果是httpd2.2版本就要加上这一行如果是2.4版本就不要加
<VirtualHost *:80>                   // 虚拟主机1配置
    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/rutime.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>                  //虚拟主机2配置
    DocumentRoot "/usr/local/apache/htdocs/wheel"
    ServerName wheel.example.com
    ErrorLog "logs/wheel.example.com-error_log"
    CustomLog "logs/wheel.example.com-access_log" common
</VirtualHost>


// 创建网站的根目录并且写入内容到index文件中
[root@100 ~]# mkdir /usr/local/apache/htdocs/runtime
[root@100 ~]# mkdir /usr/local/apache/htdocs/wheel
[root@100 ~]# apachectl -t
Syntax OK
[root@100 ~]# echo "runtime" >/usr/local/apache/htdocs/runtime/index.html
[root@100 ~]# echo "wheel" >/usr/local/apache/htdocs/wheel/index.html

[root@100 ~]# apachectl restart     //重启服务
[root@100 ~]# 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                              :::81                                           :::*                  
LISTEN      0      128                              :::22                                           :::*                  
LISTEN      0      100                             ::1:25                                           :::* 

//  修改主机端的hosts文件
[root@96 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.100 runtime.example.com           //添加服务端的ip 和域名进来
192.168.100.100 wheel.example.com           // 添加服务端的另一个ip和域名

// 验证:
// 访问runtime.example.com
[root@96 ~]# curl http://runtime.example.com
runtime
// 访问wheel.example.com
[root@96 ~]# curl http://wheel.example.com
wheel

// DocumentRoot “/usr/local/apache/htdocs/wheel” 网页的目录站点不是固定的可以指定
// 例如将网站目录放在/var/www/html 则可以改为:DocumentRoot “/var/www/html/www”

将网页的目录站点放到/var/www/html日志文件放在/var/log/httpd进行一下配置:

[root@100 ~]#  vim /etc/httpd24/httpd.conf
ServerName www.example.com:80       //取消此行前面的#号

`[root@100 ~]#  vim /etc/httpd24/httpd.conf
//在配置文件的最后加上如下内容
#虚拟主机 1 配置:
<VirtualHost 192.168.100.100:80>
    ServerName runtime.example.com
    DocumentRoot "/var/www/html/www"
    ErrorLog "/var/log/httpd/www/error_log"
    CustomLog "/var/log/httpd/www/access_log" combined
    <Directory /var/www/html/www>
        <RequireAll>
        Require all granted
        </RequireAll>
    </Directory>
</VirtualHost>

#虚拟主机 2 配置:
<VirtualHost 192.168.100.100:80>
    ServerName wheel.example.com
    DocumentRoot "/var/www/html/blog"
    ErrorLog "/var/log/httpd/blog/error_log"
    CustomLog "/var/log/httpd/blog/access_log" combined
    <Directory /var/www/html/blog>
        <RequireAll>
        Require all granted
        </RequireAll>
    </Directory>
</VirtualHost>
注意:httpd-2.4版本默认是拒绝所有主机访问的,所以安装以后必须做显示授权访问


// 创建网站目录并修改属主和属组为Apache
[root@100 ~]# cd /var/www/html/
[root@100 html]# mkdir www blog
[root@100 html]# ls
blog  www

[root@100 html]# chown -R apache.apache blog
[root@100 html]# chown -R apache.apache www
[root@100 html]# ll
总用量 0
drwxr-xr-x. 2 apache apache 6 6月  19 16:23 blog
drwxr-xr-x. 2 apache apache 6 6月  19 16:23 www

[root@100 html]# echo "www.baidu.com" >www/index.html
[root@100 html]# echo "blog.it.com" >blog/index.html



// 创建相应的日志目录并修改属主和属组为Apache
[root@100 html]# mkdir /var/log/httpd/{www,blog}
[root@100 html]# ls /var/log/httpd/
  blog  www

[root@100 html]# chown -R apache.apache /var/log/httpd/
[root@100 html]# ll /var/log/httpd/
drwxr-xr-x. 2 apache apache     6 6月  19 16:28 blog
drwxr-xr-x. 2 apache apache     6 6月  19 16:28 www

// 重启服务   [root@100 httpd]# apachectl restart
查看是否有80端口
[root@100 html]# 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                    :::*  


//  修改主机端的hosts文件
[root@96 ~]# vim /etc/hosts
# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
//  添加以下两行
192.168.100.100 runtime.example.com       
192.168.100.100 wheel.example.com  

// 主机进行验证:
[root@96 ~]# curl http://runtime.example.com
www.baidu.com
[root@96 ~]# curl http://wheel.example.com
blog.it.com
[root@96 ~]# 

。ssl

启用模块:
yum 安装的情况下:
编辑/etc/httpd/conf.modules.d/00-base.conf文件,添加下面这行,如果已经有了但是注释了,则取消注释即可
LoadModule ssl_module modules/mod_ssl.so

源码安装的情况下:

[root@100 httpd]# vim /etc/httpd24/httpd.conf
LoadModule ssl_module modules/mod_ssl.so        //将此行注释取消掉

。https配置:

环境说明:

服务端 客户端
192.168.100.100 192.168.100.96

// openssl实现私有CA:
CA的配置文件:/etc/pki/tls/openssl.cnf
a) CA生成一对密钥

[root@96 ~]# cd /etc/pki/CA
[root@96 CA]# ls
certs  crl  newcerts  private

[root@96 CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
.............+++
................+++
e is 65537 (0x10001)

[root@96 CA]# openssl rsa -in private/cakey.pem -pubout

b) CA生成自签署证书

[root@96 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HuBei
Locality Name (eg, city) [Default City]:WuHan
Organization Name (eg, company) [Default Company Ltd]:runtime.example.com
Organizational Unit Name (eg, section) []:runtime.example.com
Common Name (eg, your name or your server's hostname) []:runtime.example.com
Email Address []:1@2.com

[root@96 CA]# openssl x509 -text -in cacert.pem      //读出证书的内容
内容略。。。。
[root@96 CA]# mkdir certs newcerts crl        //创建目录

[root@96 CA]# touch index.txt && echo 01 > serial
[root@96 CA]# ls
cacert.pem  certs  crl  index.txt  newcerts  private  serial
[root@96 CA]# cat serial 
01

c) 服务端生成密钥

[root@100 ~]# cd /etc/httpd24 && mkdir ssl && cd ssl
[root@100 ssl]# 

[root@100 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus
.....................+++
................+++
e is 65537 (0x10001)
[root@100 ssl]# 

d) 服务端生成证书签署请求

[root@100 ssl]# openssl req -new -key httpd.key -days 365 -out httpd.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HuBei
Locality Name (eg, city) [Default City]:WuHan
Organization Name (eg, company) [Default Company Ltd]:runtime.example.com
Organizational Unit Name (eg, section) []:runtime.example.com
Common Name (eg, your name or your server's hostname) []:runtime.example.com
Email Address []:1@2.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:                          //不设置密码直接回车
An optional company name []:
[root@100 ssl]# 

e) 服务端把证书签署请求文件发送给CA

[root@100 ssl]# scp httpd.csr root@192.168.100.96:/root
httpd.csr                                                            100% 1082    21.2KB/s   00:00    
[root@100 ssl]# 

[root@96 CA]# cd
[root@96 ~]# ls
httpd.csr

f) CA签署服务端提交上来的证书

[root@96 ~]# openssl ca -in /root/httpd.csr -out httpd.crt -days 365
[root@96 ~]# ls
httpd.crt     httpd.csr

g) CA把签署好的证书httpd.crt发给服务端

[root@96 ~]# scp httpd.crt root@192.168.100.100:/root/
[root@100 ~]# ls
httpd.crt 
[root@100 ~]# mv httpd.crt /etc/httpd24/ssl/
[root@100 ~]# cd /etc/httpd24/ssl/
[root@100 ssl]# ls
httpd.crt  httpd.csr  httpd.key
[root@100 ssl]# 

// ssl配置:

// 配置虚拟主机
[root@100 ~]# vim /etc/httpd24/extra/httpd-ssl.conf 
/DocumentRoot   //搜索
修改为以下内容:
DocumentRoot "/usr/local/apache/htdocs/runtime"
ServerName runtime.example.com:443
ServerAdmin you@example.com
ErrorLog "/usr/local/apache/logs/runtime.example.com-error_log"
TransferLog "/usr/local/apache/logs/runtime.example.com-access_log"
紧接着将
 SSLCertificateFile "/etc/httpd24/server.crt"  改为 SSLCertificateFile "/etc/httpd24/ssl/httpd.crt"
SSLCertificateKeyFile "/etc/httpd24/server.key"  改为   SSLCertificateKeyFile "/etc/httpd24/ssl/httpd.key"

//配置完成之后检查一下配置文件是否有语法错误:
[root@100 httpd24]# apachectl -t
Syntax OK

[root@100 httpd24]# vim httpd.conf
Include /etc/httpd24/extra/httpd-ssl.conf    //将此行的注释取消
LoadModule ssl_module modules/mod_ssl.so   //将此行的注释取消

[root@100 httpd24]# vim extra/httpd-ssl.conf 
#SSLSessionCache        "shmcb:/usr/local/apache/logs/ssl_scache(512000)"  //此行添加注释

//修改完成之后检查一下配置文件是否有语法错误:
[root@100 httpd24]# apachectl -t
Syntax OK

//重启服务
[root@100 httpd24]# apachectl restart

//查看https端口(443)起来没有
[root@100 httpd24]# ss -antl
State       Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN      0      50                      *:139                                 *:*                  
LISTEN      0      128                     *:111                                 *:*                  
LISTEN      0      128                     *:22                                  *:*                  
LISTEN      0      100             127.0.0.1:25                                  *:*                  
LISTEN      0      50                      *:445                                 *:*                  
LISTEN      0      128                     *:44643                               *:*                  
LISTEN      0      50                     :::139                                :::*                  
LISTEN      0      128                    :::111                                :::*                  
LISTEN      0      128                    :::80                                 :::*                  
LISTEN      0      128                    :::22                                 :::*                  
LISTEN      0      100                   ::1:25                                 :::*                  
LISTEN      0      128                    :::443                                :::*          //443端口起来了

修改客户端的hosts文件
C:\Windows\System32\drivers\etc\hosts
192.168.100.100 runtime.example.com

//访问结果:
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CentOS7搭建httpd服务 的相关文章

  • Android的服务Service

    Android学了太久了 都忘了 复习下四大组件之一的Service 介绍 Android的Service是一种在后台执行长时间运行操作的组件 它可以在没有用户界面的情况下执行任务 并且可以与应用程序的其他组件进行通信 Service通常用
  • 自制个人图床

    如何自制个人图床 有时候我们想要将自己的图片以链接的形式展示 就得需要使用图床 或者上传到自己的服务器 别人的图床会担心图片链接过期 然而自己的服务器会占用内存资源 所以我们就自制个人图床 首先你得有服务器和域名 好了废话不多说直接上教程
  • uniapp连接蓝牙相关问题

    设备蓝牙连接成功 获取不到设备蓝牙服务列表 这种情况一般会接收到uniapp的错误码 10004 我们可以前往uniapp官网API模块查看错误码信息 查看后可以得知错误码10004是没有找到指定服务 我们可以详细看下获取所有服务的api
  • linux下Oracle服务的启动和关闭

    1 前言 确保我们能够访问oracle数据库包含两部分 一个是oracle实例 一个是监听 两个同时开启 我们才能正常的使用数据库 因此我们在关闭和启动oracle服务时 也需要同时操作实例和监听 能够操作linux的工具有很多 如 xsh
  • apple mobile device服务无法启动,错误1053 解决

    本文转载自 https www cnblogs com relax p 3476741 html 作者 relax 转载请注明该声明 我不想安装iTunes 于是下了iTunes64安装包 解压后得到6个文件 安装完 AppleMobile
  • 电脑优化导致打印机无法使用的问题

    使用打印机需要一些服务和端口 我经常看到因系统优化导致无法使用打印机的问题 主要有以下两种情况 一 sploov服务被关闭 sploov服务是打印机服务 必须开启 二 139或445端口被关闭 进行文件共享和打印机共享等实际通信 Windo
  • iptables开启日志

    ifconfig eth1 promisc iptables A INPUT j LOG log prefix iptables iptables nvL
  • mysql8.0一 服务启动

    声明 本文 禁止转载 本文所有观点和概念都系个人总结 难免存在疏漏之处 为不至于诱导初学者误入歧途 望各位以自己实践为准 特此声明 如有错误请告知 启动 流程 windows 7系统 创建data空目录 创建my ini文本文件 内容如下
  • Prometheus+grafana

    Prometheus grafana 文章目录 Prometheus grafana 安装部署 常用指标监控 进程监控 docker容器的监控 安装部署 使用docker的方式部署 1 创建项目目录 root 129 mkdir home
  • 基于Spring Cloud Alibaba搭建nacos

    关系 Spring Boot是框架 将各个组件集合在一起 方便快速开发web应用 Spring Cloud基于Spring Boot 限定了一组特定的组件 从而可以方便地进行微服务工程的开发 Spring Cloud Alibaba在Spr
  • SSL/TLS一键配置工具-IISCrypto

    IIS Crypto 是一个免费工具 使管理员能够在 Windows Server 2008 2012 2016 2019 和 2022 上启用或禁用协议 密码 哈希和密钥交换算法 允许您重新排序 IIS 提供的 SSL TLS 密码套件
  • Ubuntu安装Redis

    安装环境 Ubuntu 18 04 64位 一 安装 1 1 更新仓库 非必须 sudo apt update 1 2 使用 apt 从官方 Ubuntu 存储库来安装 Redis sudo apt get install redis se
  • Windows中使用Docker安装Redis

    1 拉取Redis 以管理员身份运行CMD 执行如下命令拉取Redis docker pull redis 2 在D盘新建目录D Net Program Net Docker Redis 在D盘新建D Net Program Net Doc
  • kubectl proxy 命令使用

    kubectl proxy address 192 168 8 220 accept hosts localhost 127 0 0 1 1 accept paths
  • rsync实时同步

    rsync实时同步 文章目录 rsync实时同步 toc 一 简介 二 特性 三 常用选项 四 部署 1 目标服务器操作 2 源服务器操作 3 设置脚本开机自启 一 简介 rsync是Linux系统下的数据镜像备份工具 从字面意思上 rsy
  • CentOS7搭建httpd服务

    文章目录 httpd 1 httpd安装 使用yum安装 httpd命令 curl命令 编译安装httpd 2 4 2 httpd常用配置 访问控制法则 3 虚拟主机 相同ip不同端口的配置 不同IP相同端口配置 相同IP相同端口不同域名配
  • apache24服务启动

    声明 本文 禁止转载 本文所有观点和概念都系个人总结 难免存在疏漏之处 为不至于诱导初学者误入歧途 望各位以自己实践为准 特此声明 如有错误请告知 服务 链接 https pan baidu com s 1VS xSo3eC7TxihciN
  • RPC

    RPC 远程过程调用 是什么 简单的说 RPC就是从一台机器 客户端 上通过参数传递的方式调用另一台机器 服务器 上的一个函数或方法 可以统称为服务 并得到返回的结果 RPC 会隐藏底层的通讯细节 不需要直接处理Socket通讯或Http通
  • 【微服务】一张图搞懂微服务架构设计

    一张图搞懂微服务架构设计 1 前言 2 流量入口 Nginx 3 网关 4 业务组件 5 服务注册中心 6 缓存和分布式锁 7 数据持久层 8 结构型数据存储 9 消息中间件 10 日志收集 11 任务调度中心 12 分布式对象存储 1 前
  • 关闭WIN10的wsappx进程服务

    关闭原因 打开电脑登录系统后 发现wsappx进程服务占用CPU极高 并且一直没有降低 如下图所示 解决办法 将以下注册表的值由3修改为4重启系统即可 计算机 HKEY LOCAL MACHINE SYSTEM CurrentControl

随机推荐

  • Bootstarp学习教程(12) 导航组件

    导航 Bootstrap中可用的导航有相似的标记 用基类 nav开头 这是相似的部分 改变修饰类可以改变样式 标签页 注意 nav tabs类需要 nav基类
  • Mathematica学习笔记

    Mathematica学习笔记 mathematica 使用总结 1 基础知识 1 从1开始编号输入 Line 1 2 函数的另一种表达形式 1 2 3 4 5 6 7 8 MatrixForm 3 跳出死循环 如不小心进入死循环 可以采用
  • 软件设计师---数据库

    数据库 出题形式 概念数据模型 概念数据模型定义 概念数据模型常用术语 结构数据模型 关系模型 真题 三级模式结构 真题 两级映像 真题 关系模型的基本术语 关系 关系模式等 五个码 键 完整性约束 关系模式的定义 关系模式的组成 关系数据
  • 基于Android+OpenCV+CNN+Keras的智能手语数字实时翻译——深度学习算法应用(含Python、ipynb工程源码)+数据集(三)

    目录 前言 总体设计 系统整体结构图 系统流程图 运行环境 模块实现 1 数据预处理 2 数据增强 3 模型构建 4 模型训练及保存 1 模型训练 2 模型保存 5 模型评估 相关其它博客 工程源代码下载 其它资料下载 前言 本项目依赖于K
  • 简单洗牌(打乱52个随机生成的数字)

    代码如下 include
  • 操作系统学习(六)进程的基本知识

    一 程序和进程 程序 1 指令序列 2 程序段存放指令序列 数据段存放程序运行中的产生的数据 例如定义的变量 进程 1 程序的一次动态执行 进程的动态性 完成程序的并发执行 2 进程实体 进程映像 3 进程是进程实体的运行过程 是系统进行资
  • 基于卷积神经网络的脱机手写签名识别(Pytorch,Opencv,CNN)

    文章目录 前言 resnet18模型结构 resnet18实现代码 数据集 训练模型 项目结构 前言 最近做了一个手写签名识别的项目 即判断签名的真伪 使用的深度学习框架为Pytorch Opencv等等 数据集中共包含17个人的签名 使用
  • Double保留指定小数位数的五种方法

    方法一 方法一 public void test1 double d 0 3456789 BigDecimal bd new BigDecimal d double test1 bd setScale 2 BigDecimal ROUND
  • hyperledger fabric各版本更新内容

    fabric各版本文档 fabric各版本更新内容 fabric 最新版本 fabric2 5更新内容 fabric2 4更新内容 fabric2 3更新内容 fabric2 2更新内容 fabric2 1更新内容 fabric2 0更新内
  • Ansible中vars(变量)定义

    1 变量使用的原因 playbook的编写是使用yml的语法 虽然该语法规则较为简单 但是 同其他语法相同该语法也有变量 循环等机制的使用 变量的使用就是为了提高我们所写剧本的复用性 当某个参数更改时 直接更改变量的赋值 无需更改剧本中的每
  • 最近大热的 chatGPT 会取代你的工作吗?

    ChatGPT 由于其高效的自然语言处理能力 它最容易取代的领域可能是 文本分类 ChatGPT 可以用作文本分类系统 对文本进行分类 聊天机器人 ChatGPT 可以制作聊天机器人 提供人性化的交互体验 文本生成 ChatGPT 可以生成
  • 小米生态企业强力推荐的开源免费SRM采购管理平台功能介绍

    本文节选自Odoo亚太金牌服务机构 开源智造 所编写的 ERP真的免费不花钱 Odoo应用指南 如需获取完整的知识内容 请至开源智造官网免费获取 感谢网友一键三连 点赞 转发 收藏 您的支持是我们最大的前进动力 概述 采购工作起源于采购请求
  • swagger设置字段required必填

    swagger注解中需要设置请求参数的字段是必须填写的还是非必须的 我们需要添加下面的配置 只需要在对象的字段中增加下面的代码 ApiModelProperty value 自建应用的corpid required true 显示效果如下
  • Vulnhub实战-prime1

    前言 VulnHub 是一个面向信息安全爱好者和专业人士的虚拟机 VM 漏洞测试平台 它提供了一系列特制的漏洞测试虚拟机镜像 供用户通过攻击和漏洞利用的练习来提升自己的安全技能 本次 我们本次测试的是prime1 一 主机发现和端口扫描 查
  • Python 、Pychorm 、 Opencv安装及环境变量的配置--opencv不能调用cv2

    Python Pychorm Opencv安装及环境变量的配置 Python安装及环境变量的配置 1 Python下载安装 官网下载Python安装包 Python官网 https www python org Python在安装时 提示可
  • flex 一行两个_flex 方式的布局你用对了吗?

    对于 CSS 中的 flex 弹性布局 曾经我在公众号里写过 一点点对 flex 布局有关的看法 和 又一次想说 flex 布局挖坑给你 信吗 印象中最深的一个点 是我在文中提到的对于 flex 的这个属性中的三个属性值怎么用的话题 如果你
  • 初等变换法求解线性方程组

    初等变换 通过初等行 列同理 变换把增广矩阵变为简化阶梯型矩阵的线性方程组求解算法 具体步骤 枚举每一列 找到枚举的当前列绝对值最大数的所在行 将该行换到最上面一行 第r行 将该行第一个数 该行第c列元素 消成1 将该行第一个元素 该行第c
  • PCB中如何区分电源线和信号线

    在电路设计中 我们需要区分电源线和信号线 电源线主要负责传输电能和提供稳定的电压给整个电路系统 而信号线则传输各种数据 信息和控制电路 当我们开始画 PCBA 时 通常会采用颜色编码来区分电源线和信号线 以下是一些常见的方法 电源线通常使用
  • 常用邮件客户端软件设置

    文章来源 http service mail qq com cgi bin help subtype 1 id 28 no 371 2 您可以使用支持POP3的客户端软件 例如Foxmail或Outlook 收发您的邮件 请配置您的电子邮件
  • CentOS7搭建httpd服务

    文章目录 httpd 1 httpd安装 使用yum安装 httpd命令 curl命令 编译安装httpd 2 4 2 httpd常用配置 访问控制法则 3 虚拟主机 相同ip不同端口的配置 不同IP相同端口配置 相同IP相同端口不同域名配