Http和Https配置


HTTP配置

虚拟主机

虚拟主机有三类

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

相同IP不同端口

[root@100 ~]# vim /etc/httpd/conf/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			将前面的#去掉

[root@100 ~]# find / -name *vhosts.conf
/usr/share/doc/httpd/httpd-vhosts.conf
[root@100 ~]# cp /usr/share/doc/httpd/httpd-vhosts.conf /etc/httpd/conf.d/
[root@100 ~]# cd /etc/httpd/conf.d/
[root@100 conf.d]# ls
autoindex.conf  httpd-vhosts.conf  manual.conf  README  userdir.conf  welcome.conf
[root@100 conf.d]# vim httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/html/tank"
    ServerName www.tank100.com
    ErrorLog "/var/log/httpd/www.tank100.com-error_log"
    CustomLog "/var/log/httpd/www.tank100.com-access_log" common
</VirtualHost>

Listen 81
<VirtualHost *:81>
    DocumentRoot "/var/www/html/poker"
    ServerName www.poker233.com
    ErrorLog "/var/log/httpd/www.poker100.com-error_log"
    CustomLog "/var/log/httpd/www.poker100.com-access_log" common
</VirtualHost>

[root@100 conf.d]# httpd -t
Syntax OK
[root@100 conf.d]# systemctl restart httpd

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


不同IP相同端口

[root@100 conf.d]# vim httpd-vhosts.conf
<VirtualHost 192.168.159.100:80>
    DocumentRoot "/var/www/html/tank"
    ServerName www.tank100.com
    ErrorLog "/var/log/httpd/www.tank100.com-error_log"
    CustomLog "/var/log/httpd/www.tank100.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.159.101:80>
    DocumentRoot "/var/www/html/poker"
    ServerName www.poker233.com
    ErrorLog "/var/log/httpd/www.poker100.com-error_log"
    CustomLog "/var/log/httpd/www.poker100.com-access_log" common
</VirtualHost>

[root@100 conf.d]# httpd -t
Syntax OK
[root@100 conf.d]# systemctl restart httpd
[root@100 conf.d]# ip addr add 192.168.159.101/24 dev ens33
[root@100 conf.d]# ip a |grep ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 192.168.159.100/24 brd 192.168.159.255 scope global noprefixroute ens33
    inet 192.168.159.101/24 scope global secondary ens33

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


相同IP相同端口不同域名

[root@100 conf.d]# vim httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/html/tank"
    ServerName www.tank100.com
    ErrorLog "/var/log/httpd/www.tank100.com-error_log"
    CustomLog "/var/log/httpd/www.tank100.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/html/poker"
    ServerName www.poker233.com
    ErrorLog "/var/log/httpd/www.poker100.com-error_log"
    CustomLog "/var/log/httpd/www.poker100.com-access_log" common
</VirtualHost>

[root@100 conf.d]# httpd -t
Syntax OK
[root@100 conf.d]# systemctl restart httpd

Linux修改hosts文件

[root@100 ~]# vim /etc/hosts
192.168.159.100 www.tank100.com www.poker233.com

[root@100 ~]# curl www.tank100.com
<!DOCTYPE html>
<html lang="zh" class="no-js demo-1">
        <head>
                <meta charset="UTF-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <script src="js/jquery.min.js"></script>
                <script src="js/Helper.js"></script>
                <script src="js/keyboard.js"></script>
                <script src="js/const.js"></script>
                <script src="js/level.js"></script>
                <script src="js/crackAnimation.js"></script>
                <script src="js/prop.js"></script>
                <script src="js/bullet.js"></script>
                <script src="js/tank.js"></script>
                <script src="js/num.js"></script>
                <script src="js/menu.js"></script>
                <script src="js/map.js"></script>
                <script src="js/Collision.js"></script>
                <script src="js/stage.js"></script>
                <script src="js/main.js"></script>
                <link rel="stylesheet" type="text/css" href="css/default.css" />
                <style type="text/css">
                        #canvasDiv canvas{
                                position:absolute;
                        }
                </style>
        </head>
        <body>
                <div class="container">
                        <head><h3>操作说明:玩家1:wasd上左下右,space射击;玩家2:方向键,enter射击。n下一关,p上一关。</h3></head>
                        <div class="main clearfix">
                                <div id="canvasDiv" >
                                        <canvas id="wallCanvas" ></canvas>
                                        <canvas id="tankCanvas" ></canvas>
                                        <canvas id="grassCanvas" ></canvas>
                                        <canvas id="overCanvas" ></canvas>
                                        <canvas id="stageCanvas" ></canvas>
                                </div>
                        </div>

                </div><!-- /container -->
                <div style="text-align:center;">
<p>来源:<a href="http://www.mycodes.net/" target="_blank">源码之家</a></p>
</div>

        </body>
</html>

Windows修改hosts文件

将C:\Windows\System32\drivers\etc\hosts拖到桌面用记事本打开进行修改
在最后一行添加
192.168.159.100 www.tank100.com www.poker233.com
保存后再将hosts文件拖回C:\Windows\System32\drivers\etc\下

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


HTTPS配置

查询有没有ssl模块和其配置文件

[root@100 ~]# httpd -M |grep ssl
[root@100 ~]#

安装ssl模块

[root@100 ~]# dnf -y install mod_ssl
[root@100 ~]# ls /etc/httpd/conf.modules.d |grep ssl
00-ssl.conf
[root@100 ~]# cd /etc/httpd/conf.modules.d/
[root@100 conf.modules.d]# cat 00-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
[root@100 conf.modules.d]# httpd -M |grep ssl
AH00526: Syntax error on line 85 of /etc/httpd/conf.d/ssl.conf:
SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty

生成私有证书

[root@100 ~]# mkdir -p /etc/pki/CA/private
[root@100 ~]# cd /etc/pki/CA/
[root@100 CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.........................................................+++++
...................+++++
e is 65537 (0x010001)

[root@100 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) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:www.tank100.com
Email Address []:11@22.com

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

[root@100 CA]# cd /etc/httpd && mkdir ssl && cd ssl
[root@100 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
....+++++
.....................+++++
e is 65537 (0x010001)
[root@100 ssl]# openssl req -new -key httpd.key -days 365 -out httpd.csr
Ignoring -days; not generating a certificate
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) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:www.tank100.com
Email Address []:11@22.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

[root@100 ssl]# openssl ca -in /etc/httpd/ssl/httpd.csr -out httpd.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jul 21 11:49:54 2022 GMT
            Not After : Jul 21 11:49:54 2023 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HB
            organizationName          = Default Company Ltd
            commonName                = www.tank100.com
            emailAddress              = 11@22.com
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                A5:DA:2D:F7:18:12:93:BF:57:CF:9D:32:F7:70:8E:F4:60:DD:0A:A0
            X509v3 Authority Key Identifier:
                keyid:E1:1B:8D:28:DD:A3:AF:49:53:6D:1D:6F:CA:25:FC:E4:D9:78:41:4E

Certificate is to be certified until Jul 21 11:49:54 2023 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

[root@100 ~]# vim /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/httpd/ssl/httpd.crt

#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#   ECC keys, when in use, can also be configured in parallel
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

[root@100 ~]# httpd -t
Syntax OK
[root@100 ~]# systemctl restart httpd

在这里插入图片描述


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值