apache配置https

一、yum 安装openssl和openssl-devel,httpd-devel
二、生成证书(也可以从公司的证书颁发机构获取):
#建立服务器密钥
openssl genrsa -des3 1024 > /usr/local/apache/conf/server.key
# 从密钥中删除密码(以避免系统启动后被询问口令)
openssl rsa -in /usr/local/apache/conf/server.key > /usr/local/apache/conf/server2.key
mv /usr/local/apache/conf/server2.key /usr/local/apache/conf/server.key
#建立服务器密钥请求文件
openssl req -new -key /usr/local/apache/conf/server.key -out /usr/local/apache/conf/server.csr
5>openssl x509 -in /usr/local/apache/conf/server.csr -out
# 建立服务器证书
/usr/local/apache/conf/server.crt -req -signkey /usr/local/apache/conf/server.key -days 365
三、修改Apache的配置文件httpd.conf

打开ssl模块,没有这个模块就需要安装依赖包:mod_ssl,安装后就会在modules里面找到:

LoadModule ssl_module         modules/mod_ssl.so

引入ssl配置文件,增加支持ssl:

Include conf/extra/httpd-ssl.conf(去掉行首的注释)
  • 启动重定向(可选),使用用户HTTP访问自动重定向为HTTPS,直接在http.conf最后配置即可,在httpd.conf文件尾加入如下内容:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
四、修改加密文件ssl.conf,通过yum安装好的httpd,在conf.d目录下面有ssl.conf配置文件,我们需要在里面配置一个VirtualHost和配置证书和密钥:
LoadModule ssl_module modules/mod_ssl.so
Listen 443
SSLPassPhraseDialog builtin
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout 300
SSLMutex default
SSLRandomSeed startup file:/dev/urandom 256
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW:!RC4: <VirtualHost _default_:443> # 必须有一个虚拟主机,这样才可以使用跳转功能和使用443端口访问
DocumentRoot "/home/store/webroot"
Servername https://xxx.com/
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on
SSLCertificateFile /etc/httpd/conf/cert/xxx.com.crt
SSLCertificateKeyFile /etc/httpd/conf/cert/xxx.com.key
</VirtualHost>
五、重启Apache

service httpd restart

  1. 在浏览器输入https://域名 或者 域名:443,如果两个能正常访问,表示https已经配置成功。
  2. 在浏览器输入 域名,如果能够正常跳转到https连接上,那说明跳转功能正常。
  • 启动apache 碰到下面问题:
Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration

到apache的bin 目录下面执行 ./httpd -l 看看有没有mode_ssl.c,这个错误说明ssl模块安装没有成功。

解决办法:

  • 1、重新编译apache,加上--enable-ssl --with-ssl参数

  • 2、把ssl模块加入到已经编译好的apache中

    首先,使用 whereis openssl 命令获取lib和include的路径

[root@robot /usr/local/apache/modules]# whereis openssl
openssl: /usr/bin/openssl /usr/lib/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz

然后 在apache 源码的modules/ssl文件夹下,使用命令/usr/sbin/apxs -i -a -D HAVE_OPENSSL=1 -I/usr/include/openssl/ -L/usr/lib/openssl/ -c *.c -lcrypto -lssl -ldl (apxs需要安装http-devel才有,虽然如此,我还是没有编译成功,于是就在其他已经编译了这个模块的机器上拷贝mod_ssl.so到apache模块目录/usr/local/apache/modules)

Apache配置HTTPS功能的更多相关文章

  1. Linux下Apache配置HTTPS功能

    Apache配置HTTPS功能  转 https://www.cnblogs.com/liaojiafa/p/6028816.html 一.yum 安装openssl和openssl-devel,ht ...

  2. Windows上为Apache配置HTTPS

    Windows上为Apache配置HTTPS   转 https://www.cnblogs.com/tianzijiaozi/p/7582671.html   1. 安装OpenSSL: Windo ...

  3. Apache配置https

    Apache配置https 之前一直用的是Tomcat,今天突然接到任务要给Apache配置https证书,因为小程序要用.下面把过程列出来以备后续查看. 1.首先你得有ssl证书,没有的可以去购买, ...

  4. Nginx 高级配置-https 功能

    Nginx 高级配置-https 功能 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HTTPS工作过程 1>.SSL/TLS SSL(Secure Socket Lay ...

  5. mac 使用apache开启https功能,实现ios局域网内测(一)

    笔者尝试了网上各种办法最后还是找到了方法解决了一系列局域网内测的问题,随手做个笔记记录下,亲测可行. 一.先生成证书 1.进入apache web 的根目录处理证书命令 cd /Library/Web ...

  6. 在linux下的apache配置https协议,开启ssl连接

    环境:linux 配置https协议,需要2大步骤: 一.生成服务器证书 1.安装openssl软件 yum install -y openssl mod_ssl 2.生成服务器私匙,生成server ...

  7. apache 配置https(转)

    主要讲述在windows下apache配置SSL以实现http转换为https SSL: SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全.也就是说在SSL下 ...

  8. lamp之apache配置https访问

    配置apache 使用https 注:怕其他人由于路径的原因出问题,首先声明一下,本人apache的安装目录为 : /usr/local/httpd2.4.25,如果不是,请参考进行配置 注: 对于如 ...

  9. Linux Apache配置https访问

    配置https访问 该环境是rh254课程配套的一个环境,不过配置方法步骤相同. 要求: 使用虚拟主机技术部署两个网站: 网站1: 绑定域名 www0.example.com 目录在 /srv/www ...

随机推荐

  1. Codeforces Round #359(div 2)

    A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...

  2. 用Intent实现activity的跳转

    新建一个FirstAvtivity.java package com.zhuguangwei; import android.app.Activity;import android.content.I ...

  3. 链队列的C/C++实现

    #include <iostream> using namespace std; const int N = 10; typedef int ELEMTYPE; typedef struc ...

  4. [转]浅谈jQuery EasyUI的属性设置

    原文地址:http://www.easyui.info/archives/1664.html 对jQuery EasyUI有一定了解的话,应该知道基本上每一个组件都有一个"options&q ...

  5. [转]FastJSON通过SerializeFilter定制序列化

    原文地址:https://github.com/alibaba/fastjson/wiki/SerializeFilter 简介 SerializeFilter是通过编程扩展的方式定制序列化.fast ...

  6. lightoj 1370 欧拉函数

    A - Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & % ...

  7. mysql-case ... when...then...else...end处理判断赋值机制

    then jrkp else zrspj end ))/(case zrspj then jrkp else zrspj end ) zdf from hqxg order by zdf LIMIT ...

  8. 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换

    介绍背水一战 Windows 10 之 绑定 DataContextChanged - FrameworkElement 的 DataContext 发生变化时触发的事件 UpdateSourceTr ...

  9. C# 获取当前月第一天和最后一天

    废话不多说,直接上代码 //先获取当前时间 DateTime now = DateTime.Now; //获取当前月的第一天 DateTime d1 = new DateTime(now.Year, ...

  10. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    看图: