首頁 > 後端開發 > php教程 > 怎么配置apache使用https访问

怎么配置apache使用https访问

PHPz
發布: 2020-09-05 09:37:50
原創
3725 人瀏覽過

怎么配置apache使用https访问

配置apache使用https访问的方法:

准备

1

yum install mod_ssl openssl

登入後複製

生成一个自签名证书

1

cd /etc/pki/CA

登入後複製

1.生成2048位的加密私钥

1

openssl genrsa -out server.key 2048

登入後複製

2.生成证书签名请求

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

openssl req -new -key server.key -out server.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) []:beijing

Locality Name (eg, city) [Default City]:beijing

Organization Name (eg, company) [Default Company Ltd]:test.com

Organizational Unit Name (eg, section) []:test

Common Name (eg, your name or your server's hostname) []:test.com

Email Address []:test@qq.com

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:123456

An optional company name []:test

登入後複製

3.生成类型为X509的自签名证书(有效期36500天)

1

openssl x509 -req -days 36500 -in server.csr -signkey server.key -out server.crt

登入後複製

3.配置Apache服务

1

vim /etc/httpd/conf.d/ssl.conf

登入後複製

1.修改下面的内容

1

2

SSLCertificateFile /etc/pki/CA/server.crt

SSLCertificateKeyFile /etc/pki/CA/server.key

登入後複製

2.重启Apache

1

/etc/init.d/httpd restart

登入後複製

4.调整虚拟主机

1

2

cd /etc/httpd/conf.d

vim test.conf

登入後複製

添加以下内容

1

2

3

4

5

6

7

8

9

10

11

12

NameVirtualHost *:443

<VirtualHost *:443>

SSLEngine on

SSLCertificateFile /etc/pki/CA/server.crt

SSLCertificateKeyFile /etc/pki/CA/server.key

<Directory /var/www/html/>

    AllowOverride All

</Directory>

ServerAdmin email@example.com

DocumentRoot /var/www/html/

ServerName www.test.com

</VirtualHost>

登入後複製

5.测试访问

1.因为域名只是一个测试的,所以需要再Windows下绑定hosts,自定绑定

2.访问测试

1

https://Ip

登入後複製

更多相关知识,请访问PHP中文网

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板