一、準(zhǔn)備工作
1.1 安裝Apache服務(wù)器
yum install httpd -y
1.2 Apache服務(wù)器上已經(jīng)開啟了443端口
443為HTTPS服務(wù)的默認(rèn)端口
1.3 Apache服務(wù)器上已安裝了mod_ssl.so模塊
啟用SSL功能,安裝mod_ssl.so模塊
yum install -y mod_ssl
1.4 獲取SSL證書
使用Certbot簽發(fā)和續(xù)費(fèi)泛域名SSL證書:https://blog.csdn.net/cljdsc/article/details/133461361文章來源:http://www.zghlxwxcb.cn/news/detail-772125.html
二、配置apache
2.1 配置apache文件
vhost的域名配置文件.conf,在目錄:/etc/httpd/conf.d文章來源地址http://www.zghlxwxcb.cn/news/detail-772125.html
- HTTP配置:
Listen 80
# 指定域名
ServerName www.example.com
# 指定文檔根目錄
DocumentRoot /var/www/html
# 是否啟用訪問日志
CustomLog /var/log/httpd/access.log combined
# 指定錯(cuò)誤日志路徑
ErrorLog /var/log/httpd/error.log
# 配置虛擬主機(jī)
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/project
# 訪問權(quán)限
<Directory /var/www/html/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# 使用PHP解析器處理.php文件
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
# 定義PHP腳本的目錄索引
DirectoryIndex index.php index.html
# 自定義錯(cuò)誤頁(yè)面
ErrorDocument 404 /error_404.html
# 設(shè)置HTTP頭信息
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
</VirtualHost>
- HTTPS配置:
<VirtualHost *:443>
DocumentRoot /var/www/html/project
ServerName www.cpayfinance.com
ServerAlias www.cpayfinance.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/cpayfinance.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cpayfinance.com//privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/cpayfinance.com//chain.pem
# 訪問權(quán)限
<Directory /var/www/html/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# 使用PHP解析器處理.php文件
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
# 定義PHP腳本的目錄索引
DirectoryIndex index.php index.html
# 自定義錯(cuò)誤頁(yè)面
ErrorDocument 404 /error_404.html
# 設(shè)置HTTP頭信息
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
</VirtualHost>
- HTTP & HTTPS 配置
Listen 80
# 指定域名
ServerName www.cpayfinance.com
# 指定文檔根目錄
DocumentRoot /var/www/html
# 是否啟用訪問日志
CustomLog /var/log/httpd/access.log combined
# 指定錯(cuò)誤日志路徑
ErrorLog /var/log/httpd/error.log
# 配置虛擬主機(jī)
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/project
# 訪問權(quán)限
<Directory /var/www/html/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# 使用PHP解析器處理.php文件
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
# 定義PHP腳本的目錄索引
DirectoryIndex index.php index.html
# 自定義錯(cuò)誤頁(yè)面
ErrorDocument 404 /error_404.html
# 設(shè)置HTTP頭信息
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html/project
ServerName www.cpayfinance.com
ServerAlias www.cpayfinance.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/cpayfinance.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/cpayfinance.com//privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/cpayfinance.com//chain.pem
# 訪問權(quán)限
<Directory /var/www/html/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# 使用PHP解析器處理.php文件
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
# 定義PHP腳本的目錄索引
DirectoryIndex index.php index.html
# 自定義錯(cuò)誤頁(yè)面
ErrorDocument 404 /error_404.html
# 設(shè)置HTTP頭信息
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
</VirtualHost>
2.2 生效配置文件
- 查看配置文件是否正常
# apachectl -t
Syntax OK
- 重啟apache配置
systemctl restart httpd
到了這里,關(guān)于Apache配置ssl證書-實(shí)現(xiàn)https訪問的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!