如何为 Apache httpd 安装 mod_ssl?

好吧

因此,我前一阵子安装了 Apache httpd,最近又回来尝试安装 SSL,并让它服务于几个不同的 tomcat 服务器。

目前,我有两个完全独立的 Tomcat 实例,它们可以提供略有不同的版本(一个用于开发,一个用于演示) ,我的 web 应用可以提供给两个不同的端口:

  • example.com:8081
  • example.com:8082

我已经成功地(回到1月)使用 mod_jk使得 httpdhttp://www.example.com:8090/devhttp://www.example.com:8090/demo提供相同的 Tomcat 实例(8090,因为我已经在8080上通过 Jetty 运行了另一个应用程序) ,使用 httpd.conf中的以下代码:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel debug


<VirtualHost *:8090>
JkMount /devd* tomcatDev
JkMount /demo* tomcatDemo
</VirtualHost>

我没有尝试启用 SSL。

我在 httpd.conf中添加了以下内容:

Listen 443
<VirtualHost _default_:443>
JkMount /dev* tomcatDev
JkMount /demo* tomcatDemo
SSLEngine on
SSLCertificateFile "/opt/httpd/conf/localhost.crt"
SSLCertificateKeyFile "/opt/httpd/conf/keystore.key"
</VirtualHost>

但是,当我尝试用 apachectl restart重启 Apache 时(是的,在关闭了我提到的另一个应用程序,这样它就不会玩弄 https 连接) ,我不断地得到这个错误:

命令‘ SSLEngine’无效,可能由服务器配置中未包含的模块拼写错误或定义。Httpd 没有运行,正在尝试启动

我已经查看了 httpd/modules目录,确实没有 mod_ssl,只有 mod_jk.sohttpd.exp

我试过用 yum 安装 mod_ssl,它说它已经安装了。实际上我可以在 /usr/lib/httpd/modules中找到 mod_ssl.so,但这不是我安装 httpd的路径,它是 /opt/httpd,事实上 /usr/lib/httpd只包含 modules目录。

谁能告诉我如何正确安装 mod_ssl为我安装的位置的 httpd,所以我可以通过这个错误?

286655 次浏览

Are any other LoadModule commands referencing modules in the /usr/lib/httpd/modules folder? If so, you should be fine just adding LoadModule ssl_module /usr/lib/httpd/modules/mod_ssl.so to your conf file.

Otherwise, you'll want to copy the mod_ssl.so file to whatever directory the other modules are being loaded from and reference it there.

I found I needed to enable the SSL module in Apache (obviously prefix commands with sudo if you are not running as root):

a2enmod ssl

then restart Apache:

/etc/init.d/apache2 restart

More details of SSL in Apache for Ubuntu / Debian here.

Try installing mod_ssl using following command:

yum install mod_ssl

and then reload and restart your Apache server using following commands:

systemctl reload httpd.service
systemctl restart httpd.service

This should work for most of the cases.

I used:

sudo yum install mod24_ssl

and it worked in my Amazon Linux AMI.

I don't know if it is still of interest and if things have changed ever since the thread has been posted, but the /etc/apache2/apache2.conf on my system says:

Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ directories contain particular configuration snippets which manage modules, global configuration fragments, or virtual host configurations, respectively.

They are activated by symlinking available configuration files from their respective *-available/ counterparts. These should be managed by using our helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See their respective man pages for detailed information.

And on my system the modules are installed in /usr/lib/apache2/modules. I am running Ubuntu 20.04.2 LTS.