虚拟主机:

虚拟主机:

虚拟主机有三类:

相同IP不同端口

[root@128 conf]# vim httpd.conf
# 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@128 conf.d]# vim httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/var/www/html/tanke"
    ServerName www.tanke1.com
    ErrorLog "/var/log/httpd/www.tanke1.com-error_log"
    CustomLog "/var/log/httpd/www.tanke1.com-access_log" common
</VirtualHost>

<VirtualHost *:81>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@128 html]# httpd -t
Syntax OK
[root@128 html]# systemctl restart httpd
[root@128 html]# ss -antl
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                         *:80                        *:*                    
LISTEN     0          128                         *:81                        *:*                    
LISTEN     0          128                      [::]:22                     [::]:*                

不同IP相同端口

[root@128 conf.d]# vim httpd-vhosts.conf
<VirtualHost 192.168.207.128:80>
    DocumentRoot "/var/www/html/tanke"
    ServerName www.tanke1.com
    ErrorLog "/var/log/httpd/www.tanke1.com-error_log"
    CustomLog "/var/log/httpd/www.tanke1.com-access_log" common
</VirtualHost>

Listen 81
<VirtualHost 192.168.207.129:81>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@128 conf.d]# httpd -t
Syntax OK
[root@128 conf.d]# systemctl restart httpd
[root@128 conf.d]# ip addr add 192.168.207.129/24 dev eth0
[root@128 conf.d]# ip a

相同IP相同端口不同域名

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

<VirtualHost *:80>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@128 conf.d]# httpd -t
Syntax OK
[root@128 conf.d]# systemctl  restart httpd

配置https

安装ssl
[root@128 ~]# yum install -y mod_ssl
生成密钥
[root@128 ~]# mkdir /etc/pki/CA
[root@128 ~]# cd /etc/pki/CA 
[root@128 CA]# mkdir private
[root@128 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@128 CA]# openssl rsa -in private/cakey.pem -pubout
writing RSA key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoH8gkQCmvjzgpUF4U4iu
EwClvHbp6sUa+ePqC/xMPBhtOwzuGEuFeV5mf/EqAzMcKIN+2PaVk9yEojGsqE6B
5ifrsaeV/IDeX+AReztM6nWgaSt1+1UmXyJjGYwsh61fCCvYPMavqnMWrDzeopCe
7H1DxPQQff6MJ9DGkf5DYWIiRxeO4By7As3WGF9QwmvvI9HWlR840UVTOyNX/YVe
KR8FPQjflR1boyLnOYtB5I7qHVn5NF1R06LiehgPjlJwJtYMLnMsghrWytoVAeGr
8N3AKaqWePkbFoOjPFK7uPTmyReMzFbB2owsM3Ag8vUqS6lokchTzl9CBrje5SE4
4wIDAQAB
-----END PUBLIC KEY-----
CA生成自签署证书
[root@128 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]:runtime
Organizational Unit Name (eg, section) []:edu
Common Name (eg, your name or your server's hostname) []:www.tanke1.com
Email Address []:1@2.co,^Hm
[root@128 CA]#  openssl x509 -text -in cacert.pem
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            7b:61:d0:f2:f4:0d:5e:f7:93:2b:87:65:ed:a4:08:98:3a:d9:08:39
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = cn, ST = hb, L = wh, O = runtime, OU = edu, CN = www.tanke1.com, emailAddress = "1@2.co,\08m"
        Validity
            Not Before: Jul 22 00:33:43 2022 GMT
            Not After : Jul 22 00:33:43 2023 GMT
        Subject: C = cn, ST = hb, L = wh, O = runtime, OU = edu, CN = www.tanke1.com, emailAddress = "1@2.co,\08m"
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    00:a0:7f:20:91:00:a6:be:3c:e0:a5:41:78:53:88:
                    ae:13:00:a5:bc:76:e9:ea:c5:1a:f9:e3:ea:0b:fc:
                    4c:3c:18:6d:3b:0c:ee:18:4b:85:79:5e:66:7f:f1:
                    2a:03:33:1c:28:83:7e:d8:f6:95:93:dc:84:a2:31:
                    ac:a8:4e:81:e6:27:eb:b1:a7:95:fc:80:de:5f:e0:
                    11:7b:3b:4c:ea:75:a0:69:2b:75:fb:55:26:5f:22:
                    63:19:8c:2c:87:ad:5f:08:2b:d8:3c:c6:af:aa:73:
                    16:ac:3c:de:a2:90:9e:ec:7d:43:c4:f4:10:7d:fe:
                    8c:27:d0:c6:91:fe:43:61:62:22:47:17:8e:e0:1c:
                    bb:02:cd:d6:18:5f:50:c2:6b:ef:23:d1:d6:95:1f:
                    38:d1:45:53:3b:23:57:fd:85:5e:29:1f:05:3d:08:
                    df:95:1d:5b:a3:22:e7:39:8b:41:e4:8e:ea:1d:59:
                    f9:34:5d:51:d3:a2:e2:7a:18:0f:8e:52:70:26:d6:
                    0c:2e:73:2c:82:1a:d6:ca:da:15:01:e1:ab:f0:dd:
                    c0:29:aa:96:78:f9:1b:16:83:a3:3c:52:bb:b8:f4:
                    e6:c9:17:8c:cc:56:c1:da:8c:2c:33:70:20:f2:f5:
                    2a:4b:a9:68:91:c8:53:ce:5f:42:06:b8:de:e5:21:
                    38:e3
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier: 
                40:A9:12:F9:16:45:8C:F5:8C:3A:AD:EC:67:EC:29:32:95:67:01:EE
            X509v3 Authority Key Identifier: 
                keyid:40:A9:12:F9:16:45:8C:F5:8C:3A:AD:EC:67:EC:29:32:95:67:01:EE

            X509v3 Basic Constraints: critical
                CA:TRUE
    Signature Algorithm: sha256WithRSAEncryption
         39:de:73:c6:c5:e7:50:96:da:64:4d:77:63:9c:28:82:a7:96:
         e2:09:5a:7d:fc:ef:d7:e5:6b:65:b8:1b:6a:0e:95:e7:ca:1e:
         08:0d:09:1d:a7:8d:58:56:52:2d:2c:a6:81:d5:35:13:53:e1:
         55:ac:48:1b:5a:31:b2:7b:2c:99:30:eb:c9:05:1a:7c:84:97:
         4c:b7:a8:30:e1:75:e8:39:fe:85:ba:2c:7d:b5:6a:22:50:87:
         74:ec:db:26:c6:ab:9a:06:5d:f8:00:0e:44:43:7c:a6:3f:2a:
         a7:33:dd:97:8b:4c:c2:95:48:6d:c4:d2:dc:c6:b6:d4:fe:ce:
         d5:43:1c:42:78:5d:8a:2d:fc:d8:5b:a6:be:83:60:5e:fc:f8:
         b7:4b:51:3c:51:a7:fc:5f:5a:05:86:9d:e7:0c:b9:8d:c6:a4:
         b2:43:88:1e:f4:b8:e5:d5:08:8f:82:65:2a:ac:72:9d:9d:e2:
         1c:6b:03:8f:97:52:37:c7:f9:71:ce:61:4c:a7:5b:fc:2d:60:
         2b:67:be:51:99:8f:95:3b:a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KkS+RZFjPWMOq3sZ+wpMpVnAe4wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0B
AQsFAAOCAQEAOd5zxsXnUJbaZE13Y5wogqeW4glaffzv1+VrZbgbag6V58oeCA0J
HaeNWFZSLSymgdU1E1PhVaxIG1oxsnssmTDryQUafISXTLeoMOF16Dn+hbosfbVq
IlCHdOzbJsarmgZd+AAOREN8pj8qpzPdl4tMwpVIbcTS3Ma21P7O1UMcQnhdii38
2FumvoNgXvz4t0tRPFGn/F9aBYad5wy5jcakskOIHvS45dUIj4JlKqxynZ3iHGsD
j5dSN8f5cc5hTKdb/C1gK2e+UZmPlTuoZClGSsZoGEpOk8Ce0pL+q0CaaLFDH5yb
v9MUw18vf4VqWA2/Lh1njqm1OzgpYTaHEA==
-----END CERTIFICATE-----
[root@128 CA]#  mkdir certs newcerts crl
[root@128 CA]# touch index.txt && echo 01 > serial
客服端生成密钥
[root@128 CA]#  cd /etc/httpd && mkdir ssl && cd ssl
[root@128 ssl]#  (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.....................................+++++
................+++++
e is 65537 (0x010001)
客户端生成证书签署请求
[root@128 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]:runtime
Organizational Unit Name (eg, section) []:edu
Common Name (eg, your name or your server's hostname) []:www.tankel
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@128 ssl]# openssl ca -in 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 22 00:37:51 2022 GMT
            Not After : Jul 22 00:37:51 2023 GMT
        Subject:
            countryName               = cn
            stateOrProvinceName       = hb
            organizationName          = runtime
            organizationalUnitName    = edu
            commonName                = www.tankel
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                7B:57:69:F0:3C:F5:12:BB:F7:CC:63:F1:29:58:6A:AD:6A:EC:EC:E3
            X509v3 Authority Key Identifier: 
                keyid:40:A9:12:F9:16:45:8C:F5:8C:3A:AD:EC:67:EC:29:32:95:67:01:EE

Certificate is to be certified until Jul 22 00:37:51 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@128 ssl]# cd /etc/httpd/conf.d/
[root@128 conf.d]# vim ssl.conf
[root@128 ~]# httpd -t
Syntax OK

23 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@128 ssl]# cd /etc/httpd/conf.d/
[root@128 conf.d]# vim ssl.conf
[root@128 ~]# httpd -t
Syntax OK


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要创建3个虚拟主机并满足上述条件,您需要进行以下步骤: 1. 在您的Web服务器上配置虚拟主机A,B和C。您需要使用不同的域名或IP地址来区分它们。例如,虚拟主机A可以是example.com,虚拟主机B可以是test.example.com,虚拟主机C可以是auth.example.com。 2. 针对虚拟主机A,您需要设置所有网段都可以访问。这可以通过在虚拟主机A的配置文件中设置以下内容来实现: ``` <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/example.com <Directory /var/www/example.com> Allow from all </Directory> ErrorLog /var/log/httpd/example.com_error.log CustomLog /var/log/httpd/example.com_access.log combined RewriteEngine On RewriteRule ^(.*)\.html$ $1.php [L] </VirtualHost> ``` 在上述配置中,DocumentRoot指定了虚拟主机A的网站根目录,<Directory>指定了访问该目录的权限,ErrorLog和CustomLog指定了日志文件的路径和格式,RewriteEngine和RewriteRule指定了URL重写规则。 3. 针对虚拟主机B,您需要设置仅内部网络可以访问。这可以通过在虚拟主机B的配置文件中设置以下内容来实现: ``` <VirtualHost *:80> ServerName test.example.com DocumentRoot /var/www/test.example.com <Directory /var/www/test.example.com> Allow from 192.168.0.0/24 Deny from all </Directory> ErrorLog /var/log/httpd/test.example.com_error.log CustomLog /var/log/httpd/test.example.com_access.log combined </VirtualHost> ``` 在上述配置中,<Directory>指定了只有内部网络可以访问的权限。 4. 针对虚拟主机C,您需要设置需要认证通过才能访问。这可以通过在虚拟主机C的配置文件中设置以下内容来实现: ``` <VirtualHost *:80> ServerName auth.example.com DocumentRoot /var/www/auth.example.com <Directory /var/www/auth.example.com> AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/httpd/conf.d/passwd Require valid-user </Directory> ErrorLog /var/log/httpd/auth.example.com_error.log CustomLog /var/log/httpd/auth.example.com_access.log combined </VirtualHost> ``` 在上述配置中,<Directory>指定了需要进行基本认证才能访问的权限,AuthUserFile指定了存储用户和密码的文件路径。 5. 虚拟主机A需要进行URL重写。这可以通过在虚拟主机A的配置文件中设置RewriteRule来实现,如上述步骤2所示。 6. 虚拟主机B需要有一个准备存放图片的目录。您可以在虚拟主机B的DocumentRoot下创建一个名为“/data/image”的目录,并将所有图片文件放入其中。 7. 虚拟主机C需要有一个只能在内部主机访问的专用目录。您可以在虚拟主机C的DocumentRoot下创建一个名为“/downloads”的目录,并在虚拟主机C的配置文件中设置以下内容来实现: ``` <VirtualHost *:80> ServerName auth.example.com DocumentRoot /var/www/auth.example.com <Directory /var/www/auth.example.com> AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/httpd/conf.d/passwd Require valid-user </Directory> <Directory /var/www/auth.example.com/downloads> Allow from 192.168.0.0/24 Deny from all </Directory> ErrorLog /var/log/httpd/auth.example.com_error.log CustomLog /var/log/httpd/auth.example.com_access.log combined </VirtualHost> ``` 在上述配置中,第一个<Directory>指定了需要进行基本认证才能访问的权限,第二个<Directory>指定了只有内部网络可以访问的权限。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值