httpd加免费证书成https

本文记录了在CentOS 7上使用Certbot安装LetsEncrypt SSL证书时遇到的问题及解决方案,特别是解决了因pyOpenSSL版本过低导致的安装失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们用的是letsencrypt的证书

letsencrypt

1.安装certbot

certbot
然后进去之后选择软件和系统

笔主的是centos7的,然后就直接yum安装

sudo yum install python-certbot-apache

然后

certbot --apache

但是笔主这里报了个错:

[root@VM_37_3_centos ~]# certbot --apache
Traceback (most recent call last):
  File "/usr/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.11.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 21, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 10, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 31, in <module>
    requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3()
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 112, in inject_into_urllib3
    _validate_dependencies_met()
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 147, in _validate_dependencies_met
    raise ImportError("'pyOpenSSL' module missing required functionality. "
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.

他说这个pyOpenssl必须要v0.14以上

我们看一下这个现有:

[root@VM_37_3_centos ~]# pip show pyOpenssl
Name: pyOpenSSL
Version: 0.13.1
Summary: Python wrapper module around the OpenSSL library
Home-page: http://pyopenssl.sourceforge.net/
Author: Jean-Paul Calderone
Author-email: exarkun@twistedmatrix.com
License: APL2
Location: /usr/lib64/python2.7/site-packages
Requires:

是0.13的。。。。醉了

好吧,卸载了重新装

pip uninstall pyOpenssl
[root@VM_37_3_centos ~]# pip uninstall pyOpenssl
DEPRECATION: Uninstalling a distutils installed project (pyOpenssl) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling pyOpenSSL-0.13.1:
  /usr/lib64/python2.7/site-packages/pyOpenSSL-0.13.1-py2.7.egg-info
Proceed (y/n)? y
  Successfully uninstalled pyOpenSSL-0.13.1

然后我们就卸载完毕了

装吧

pip install pyOpenssl

然后果然不出所料报错了

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -o build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o
    unable to execute gcc: No such file or directory
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
  Rolling back uninstall of cryptography
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-SPjUI6/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-eQZ2dp-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-SPjUI6/cryptograp````
y/
CentOS 8 中安装 Apache HTTPD(通常称为 httpd 或者 Apache)并配置SSL/TLS证书,可以按照以下步骤操作: 1. **安装 Apache**: 打开终端,首先需要更新系统包列表和安装 EPEL (Extra Packages for Enterprise Linux) 发行版,它包含额外的软件包,包括 Apache: ```sh sudo yum update -y sudo yum install epel-release -y sudo yum install httpd -y ``` 2. **启动和检查服务**: 安装完后,启动Apache服务,并设置开机自动启动: ```sh sudo systemctl start httpd sudo systemctl enable httpd ``` 检查服务状态,确认是否运行正常: ```sh sudo systemctl status httpd ``` 3. **生 SSL 证书**: 自己生证书需要一些专业知识和工具,比如 OpenSSL。一个常见的做法是在本地生自签名证书,然后上传到服务器上: ```sh openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/httpd.key -out /etc/pki/tls/certs/httpd.crt ``` 请注意这只是一个临时示例,生产环境应使用有效的CA颁发的证书。 4. **编辑配置文件**: 配置文件通常在 `/etc/httpd/conf/httpd.conf` 或 `/etc/httpd/conf.d/ssl.conf`,打开文件并添以下内容: ```conf LoadModule ssl_module modules/mod_ssl.so <VirtualHost _default_:443> DocumentRoot "/var/www/html" ServerName your_domain.com SSLEngine on SSLCertificateFile /etc/pki/tls/certs/httpd.crt SSLCertificateKeyFile /etc/pki/tls/private/httpd.key </VirtualHost> ``` 将 `your_domain.com` 替换为你的实际域名。 5. **重启服务**: 最后,记得重启Apache以应用新的配置: ```sh sudo systemctl restart httpd ``` **相关问题**: 1. 如何验证证书已生效? 2. 如何手动导入CA签发的证书? 3. 如果不想自签名证书,如何从Let's Encrypt获取免费证书
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值