Apache配置HTTPS功能

 转 https://www.cnblogs.com/liaojiafa/p/6028816.html
一、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)

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

  1. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  2. Apache配置HTTPS功能

    apache配置https 一.yum 安装openssl和openssl-devel,httpd-devel 二.生成证书(也可以从公司的证书颁发机构获取): #建立服务器密钥 openssl ge ...

  3. Linux下Apache配置SSL支持https

    参考:http://www.thinksaas.cn/group/topic/280017/ 生成证书过程如下 Step :生成服务器密钥: mkdir -p /etc/pki/test cd /et ...

  4. windows下apache配置https

    1.下载带有openSSL的apache安装包,我下载的为apache_2.2.11-win32-x86-openssl-0.9.8i.msi,安装后确认一下bin路径下的openssl.exe,ss ...

  5. Linux下Apache配置局域网访问出现的问题

    在网站安装好之后,本机可以访问,但是局域网内无法访问,我查看了 /etc/httpd/conf/httpd.conf 看到我的配置如下 <Directory ......> Allow A ...

  6. Linux下nginx配置https协议访问

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  7. Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  8. Linux下Apache的安装与配置

    本文安装的httpd版本为httpd 2.4.4安装之前确保 Development Libraries与Development tools安装上.安装方法参考:http://www.linuxidc ...

  9. Linux下apache+phppgadmin+postgresql安装配置

    Linux下apache+phppgadmin+postgresql安装配置 操作系统:CentOS 安装包:httpd(首选yum), php(包括php以及php-pgsql,php-mbstri ...

随机推荐

  1. (二叉树 BFS) leetcode102. Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  2. 【机器学习】BP & softmax求导

    目录 一.BP原理及求导 二.softmax及求导 一.BP 1.为什么沿梯度方向是上升最快方向     根据泰勒公式对f(x)在x0处展开,得到f(x) ~ f(x0) + f'(x0)(x-x0) ...

  3. 1.1浅谈Spring(一个叫春的框架)

    如今各种Spring框架甚嚣尘上,但是终归还是属于spring的东西.所以在这里,个人谈一谈对spring的认识,笔者觉得掌握spring原理以及spring所涉及到的设计模式对我们具有极大的帮助.我 ...

  4. 深入jar包:从jar包中读取资源文件getResourceAsStream

    一.背景 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等). 在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不 ...

  5. BZOJ #3625 CF #438E 小朋友和二叉树

    清真多项式题 BZOJ #3625 codeforces #438E 题意 每个点的权值可以在集合$ S$中任取 求点权和恰好为$[1..n]$的不同的二叉树数量 数据范围全是$ 10^5$ $ So ...

  6. redux知识点

    1.关于传参 点击跳转 两种 动态路由 url 但是取值需要自己处理 关于动态跳转(js执行跳转) 关于异步加载组件 创建loadable app.js中 在 要加载的异步组件中   (这样接收参数不 ...

  7. android:shape 设置圆形

    组件高度和宽度设置为相同的值即可<?xml version="1.0" encoding="utf-8"?><shape xmlns:andr ...

  8. HDMI接口之HPD(热拔插)

    HDMI (Pin 19)/DVI(Pin16)的功能是热插拔检测(HPD),这个信号将作为HDMI 源端(Source)是否发起EDID读,是否开始发送TMDS信号的依据.HPD是从HDMI显示器端 ...

  9. android SDK模拟器环境搭建

    一.下载安装android SDK 两种方式: (1)官网下载(需FQ):https://developer.android.com/studio/index.html (2)无需FQ下载:http: ...

  10. 让CPU占用率曲线听你指挥

    使用GetTickCount()和Sleep(): Code#include <stdio.h> #include <unistd.h> #include <time.h ...