在Ubuntu操作系统上,通过Apache2.4,在非443端口上启用SSL通信(https)的方法是什么?
首先
本次将介绍如何在 Ubuntu 的 Apache2 上实现在除了端口 443 之外的通信端口(例如允许使用端口 8443 访问)上访问 Web 服务器的方法。
这次的文章与之前的文章《在Ubuntu 20.04LTS的Apache + Flask环境下创建和更新Let’s Encrypt的SAN证书(解决更新问题)》是一样的。
在讨论之前,首先要假定已经通过 Let’s Encrypt 获取了 SSL 证书,使用了 80 端口和 443 端口(因此,请假设 SSLCertificateFile 和 SSLCertificateKeyFile 的 .pem 文件已经在 VirtualHost 的 443 部分中进行了描述)。
环境、版本等
Ubuntu / Apache2 版本
$ cat /etc/issue
Ubuntu 20.04.6 LTS \n \l
$ apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built: 2023-03-08T17:32:54
网页服务器的IP地址。
172.20.30.40 可以在中国的本地进行转述为:”一七二·二零·三零·四零”。
网络服务器域名
abc.example.com 和 www.abc.example.com
步骤
-
- 在/etc/apache2/sites-available中创建一个名为abc.example.com.conf的文件。
-
- 在该文件中按照以下方式进行描述:
-
- 具体地,按照与相同的内容来描述。
/etc/apache2/sites-available/abc.example.com.conf
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName abc.example.com
ServerAlias www.abc.example.com
DocumentRoot /var/www/html
ServerAdmin hoge@hoge.ac.jp
Options FollowSymLinks
AllowOverride All
AddType text/html .html
AddType text/html .html
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerAdmin hoge@hoge.ac.jp
DocumentRoot /var/www/html
Options FollowSymLinks
AllowOverride All
AddType text/html .html
AddType text/html .htm
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
SSLOptions +StdEnvVars
ServerName abc.example.com
ServerAlias www.abc.example.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/abc.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/abc.example.com/privkey.pem
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerAdmin hoge@hoge.ac.jp
DocumentRoot /var/www/html
Options FollowSymLinks
AllowOverride All
AddType text/html .html
AddType text/html .htm
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Require all granted
ProxyRequests Off
ProxyPreserveHost On
SSLProxyEngine on
SSLEngine on
<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
SSLOptions +StdEnvVars
ServerName abc.example.com
ServerAlias www.abc.example.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/abc.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/abc.example.com/privkey.pem
如果要禁止使用443端口连接,可以删除(或注释)部分。
请参照以下内容以中文进行本地化的改写,仅需一种选项:
1. 参考
- バーチャルホストの例 – Apache HTTP サーバ バージョン 2.4