Linux+Apache2.2+openssl实现https验证

简介: 下面的内容大部分来在http://djxailc.blog.sohu.com/56732044.html,他主要是针对2.0,我是在2.2上做的。2.2上的apachectl已经没有startssl选项,直接用start就可以了。

下面的内容大部分来在http://djxailc.blog.sohu.com/56732044.html,他主要是针对2.0,我是在2.2上做的。2.2上的apachectl已经没有startssl选项,直接用start就可以了。

我刚开始安装SSL时,需要mod_ssl.so这个文件,我从它的网站上只能找到Apache1.3.34的最新版本,后来咨询了几个人,看了一些资料,才发现原来Apache2.0以后不再单独提供,已经集成到了Apache的源代码里,只是编译的时候需要相关的选项而已(唉,自己知道的还是少啊)。我用下面的选项编译的:

./configure --prefix=/usr/local/apache --enable-so --enable-ssl=shared --enable-mods-shared=all --with-ssl=/usr/local/ssl

安装openssl是为了生成证书,如果你有现成的证书,则这个模块是可安装也可不安装的。

【【【(可以参照http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/dso.html学习点知识),关于把http请求重写到https,参照:http://blog.yam.com/gavint/article/13556981

由於公司之前使用 HTTP 提供某個服務給全公司,但後來考慮到安全性問題希望改用 HTTPS,但已經公佈的 HTTP 網址,不希望再通知請 User 更改習慣,於是想到 Apache 應該可以將 User 輸入的 HTTP 自動轉為 HTTPS,於是找到下面這篇文章「Apache http自動轉https」轉載於”a-wei's X garden”部落格,因為覺得很實用,所以就收錄進來,並註明出處。

引述:
apache mod_rewrite 這個模組 .. 好用的不得了 … 詳細的用法,老實說 .. 呵呵 .. 也沒研究的那麼透徹..

此筆記,主要是紀錄 apache 如何自動的從 http 非加密模式,轉移到 https 的加密法 .

httpd.conf

一、整個網站轉移
在 VirtualServer 內的 Directory

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]

二、某個目錄做自動轉移

在該目錄內


RewriteEngine on
RewriteBase /folder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

這樣就會自動轉移了
另外寫在網站目錄內的 .htaccess 也是可以的】】】】】

下面是他的原文:

apache2.0 https
  
首先安装SSL,再编译安装APACHE,再配置证书即可

1.下载apache和openssl
网址:http://www.apache.org
      http://www.openssl.org
2.解压
#tar zxvf httpd-2.0.54.tar.gz
#tar zxvf openssl-0.9.7g.tar.gz
3.编译安装openssl,这个软件主要是用来生成证书:
#cd openssl-0.9.7g
#./config
#make
#make test
#make install
把openssl放进内核目录下,使其在任何目录下都能运行。
#cd /usr/local/bin
#ln -s /usr/local/ssl/bin/openssl openssl
4.编译安装apache
#cd /opt/httpd-2.0.54
#./configure --prefix="/opt/apache2" --enable-so --enable-ssl --with-ssl="/usr/local/ssl/bin"
#make
#make install
5.安装完毕,生成证书:
在/opt/apache2/conf下建立一个ssl.key目录
#cd ../apache2/
#cd conf/
#mkdir ssl.key
然后在该目录下生成证书:
#cd ssl.key/
生成服务器私钥:
#openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.......................++++++
.................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
生成服务器证书请求,并按要求填些相关证书信息:
#openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:tyl
Organization Name (eg, company) [Internet Widgits Pty Ltd]:tz
Organizational Unit Name (eg, section) []:tz
Common Name (eg, YOUR name) []:tyl
Email Address []:tangyl@ruyi.com
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
签证:
# openssl x509 -req -days 700 -in server.csr -signkey server.key -out server.cert
Signature ok
subject=/C=AU/ST=Some-State/L=tyl/O=tz/OU=tz/CN=tyl/emailAddress=tangyl@ruyi.com
Getting Private key
Enter pass phrase for server.key:
为了安全,然后我们把这些文件的权限都设为400
chmod 400 server.key
chmod 400 server.cert

最后对/opt/apache2/conf/ssl.conf 进行修改:

vi /opt/apache2/conf/ssl.conf
修改的地方如下几处:
#SSLCertificateFile /opt/apache2/conf/ssl.crt/server.crt  #108行
SSLCertificateFile /opt/apache2/conf/ssl.key/server.cert
#SSLCertificateFile /opt/apache2/conf/ssl.crt/server-dsa.crt

SSLCertificateKeyFile /opt/apache2/conf/ssl.key/server.key   #116行
#SSLCertificateKeyFile /opt/apache2/conf/ssl.key/server-dsa.key

这样我们就基本配好了ssl现在我们来让apache启动ssl

/opt/apache2/bin/apachectl startssl

然后要求输入证书密码,正确输入后ssl就连同apache一起启动


在浏览器中输入:https://210.75.18.36

要求下载证书,OK~好了~结束~就是这么简单。

参考:http://www.szlangxing.com/Article/gyw/200504/524.html
         http://www.chinaunix.net/jh/13/469276.html

目录
相关文章
|
1月前
|
Linux 编译器 vr&ar
linux交叉编译一些常用依赖库util-linux,zlib,sqlite3,eudev ,openssl,libpng,glibc
linux交叉编译一些常用依赖库util-linux,zlib,sqlite3,eudev ,openssl,libpng,glibc
30 1
|
5月前
|
算法 Linux 网络安全
Centos7 Linux系统下生成https的crt和key证书
Centos7 Linux系统下生成https的crt和key证书
190 0
|
1月前
|
Java Linux
Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
【2月更文挑战第16天】Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
29 0
|
1月前
|
分布式计算 关系型数据库 MySQL
Sqoop【部署 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
【2月更文挑战第8天】Sqoop CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
93 1
|
28天前
|
Shell Linux C语言
【Shell 命令集合 网络通讯 】Linux 验证Samba配置文件 testparm命令 使用教程
【Shell 命令集合 网络通讯 】Linux 验证Samba配置文件 testparm命令 使用教程
31 0
|
1月前
|
算法 安全 Linux
Linux 裁剪并交叉编译openssl库
Linux 裁剪并交叉编译openssl库
26 1
|
2月前
|
前端开发 应用服务中间件 网络安全
在Apache上http强制跳转到https无效的解决办法
在Apache上http强制跳转到https无效的解决办法
|
3月前
|
Linux
Linux/CentOS设置全局代理(http)
Linux/CentOS设置全局代理(http)
212 0
|
3月前
|
Linux
Linux安装OpenSSL
Linux安装OpenSSL
|
3月前
|
Web App开发 网络协议 Linux
Linux C/C++ 开发(学习笔记十 ):实现http请求器(TCP客户端)
Linux C/C++ 开发(学习笔记十 ):实现http请求器(TCP客户端)
47 0