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

目录
相关文章
|
4月前
|
安全 网络协议 Linux
Linux网络应用层协议展示:HTTP与HTTPS
此外,必须注意,从HTTP迁移到HTTPS是一项重要且必要的任务,因为这不仅关乎用户信息的安全,也有利于你的网站评级和粉丝的信心。在网络世界中,信息的安全就是一切,选择HTTPS,让您的网站更加安全,使您的用户满意,也使您感到满意。
137 18
|
4月前
|
安全 算法 Ubuntu
Linux(openssl)环境:编程控制让证书自签的技巧。
总结:在Linux环境中,OpenSSL是一个非常实用的工具,可以帮助我们轻松地生成自签名证书。通过上述三个简单步骤,即可为内部网络、测试环境或开发环境创建自签名证书。但在公共访问场景下,建议购买经过权威认证机构签发的证书,以避免安全警告。
219 13
|
5月前
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
284 17
|
9月前
|
Ubuntu Linux Shell
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
(已成功解决)Linux环境报错—bash: wget: command not found;常见Linux发行版本,Linux中yum、rpm、apt-get、wget的区别;Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
4451 69
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
|
10月前
|
Web App开发 Linux 应用服务中间件
【DrissionPage】Linux上如何将https改为http
通过上述步骤,可以在Linux上将DrissionPage从HTTPS改为HTTP。关键在于修改DrissionPage配置、代码中的HTTPS设置、URL以及Web服务器配置,确保所有部分都正确使用HTTP协议。通过合理配置和测试,能够确保系统在HTTP环境下稳定运行。
363 1
|
11月前
|
存储 缓存 安全
https访问提示不安全,证书密钥验证上如何解决
【10月更文挑战第4天】访问提示不安全,证书密钥验证上如何解决
1364 2
|
11月前
|
安全 算法 量子技术
【HTTPS】中间人攻击和证书的验证
【HTTPS】中间人攻击和证书的验证
213 1
|
11月前
|
安全 网络安全 数据安全/隐私保护
HTTPS 请求中的证书验证详解(Python版)
HTTPS 请求中的证书验证详解(Python版)
688 0
|
Ubuntu Linux 测试技术
在Linux中,已知 apache 服务的访问日志按天记录在服务器本地目录/app/logs 下,由于磁盘空间紧张现在要求只能保留最近7天的访问日志,请问如何解决?
在Linux中,已知 apache 服务的访问日志按天记录在服务器本地目录/app/logs 下,由于磁盘空间紧张现在要求只能保留最近7天的访问日志,请问如何解决?
|
Linux Python
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
【Azure 应用服务】Azure App Service For Linux 上实现 Python Flask Web Socket 项目 Http/Https
174 0