- 简介
- 第一章 - 关于 CD
- 第二章 - 基本命令
- Hack-7 Grep
- Hack-8 Grep 与正则表达式
- Hack-9 Find 命令
- Hak-10 重定向
- Hack-11 Join 命令
- Hack-12 Tr 命令
- Hack-13 Xargs 命令
- Hack-14 Sort 命令
- Hack-15 Uniq 命令
- Hack-16 Cut 命令
- Hack-17 Stat 命令
- Hack-18 Diff 命令
- Hack-19 Ac 命令
- Hack-20 让命令在后台执行
- Hack-21 Sed 替换基础
- Hack-22 Awk 简介
- Hack-23 VIM 基本入门
- Hack-24 Chmod 命令
- Hack-25 Tail -f -f
- Hack-26 Less 命令
- Hack-27 Wget 下载器
- 第三章 - SSH 技巧
- 第四章 - 日期设置
- 第五章 - PS* 介绍
- 第六章 - 压缩和打包
- 第七章 - 历史命令
- 第八章 - 系统任务管理
- 第九章 - 安装软件
- 第十章 - LAMP 套装
- 第十一章 - Bash 脚本
- 第十二章 - 系统性能监控
- 第十三章 - 额外的技巧
Hack-75 安装 Apache2
安装 Apache2
这一篇介绍了怎样安装带有 SSL 模块的 Apache2.
(然后作者说了一大段 apache2 的优点,其实我个人还是比较倾向于 nginx 的,轻量级,配置简单,而且高并发.)
下载 Apache
从 apache 官网 下载 apache 的安装包,目前的版本是 2.4.18
(2015-12-14 发行)
➤ wget "http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.18.tar.bz2"
--2016-01-13 14:42:33-- http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.18.tar.bz2
Resolving mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160
Connecting to mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5181291 (4.9M) [application/octet-stream]
Saving to: ‘httpd-2.4.18.tar.bz2’
httpd-2.4.18.tar.bz 100%[=====================>] 4.94M 3.97MB/s in 1.2s
2016-01-13 14:42:34 (3.97 MB/s) - ‘httpd-2.4.18.tar.bz2’ saved [5181291/5181291]
➤ tar -jxf httpd-2.4.18.tar.bz2
安装 SSL 模块
➤ cd httpd-2.4.18/
➤ ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
...
...
...
配置的时候有好多选项,这里我们要安装 SSL 支持,所以:
./configure --enable-ssl --enable-so
make
make install
这样就安装好了。
在 httpd.conf
中开启 SSL
Apache 的配置文件保存在 /usr/local/apache2/conf
目录中,(如果是 apt-get 安装的话,目录则在 /etc/apache2/conf
).
把配置文件中的 #Include conf/extra/httpd-ssl.conf
前面的注释符去掉保存即可。
/usr/local/apache2/conf/extra/httpd-ssl.conf
这个文件里面保存的就是 ssl 的配置,包括公钥私钥的存放位置:
# egrep 'server.crt|server.key' httpd-ssl.conf
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
我们还需要创建一对公钥私钥才能让 apache2 正常运行,所以:
创建公私钥
openssl genrsa -des3 -out server.key 2048
上面的命令创建了一个 2048 位的密钥,其中有一步是需要你输入一个 4-1023 位长的密码,记住这个密码,以后要用到(以后也可以去掉密码的).
下一步就是创建一个 certificate request file (创建证书所用到的文件), 用到上面创建的密钥:
openssl req -new -key server.key -out server.csr
最后就是创建一个自己签发的证书了:
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
证书的时长是 365 天。
把证书复制过去
接着上面的步骤,把创建的证书和密钥都放到 apache 的配置目录中:
cp server.key /usr/local/apache2/conf/
cp server.crt /usr/local/apache2/conf/
开启 Apache
/usr/local/apache2/bin/apachectl start
过程中需要输入刚才记录的密码:
Apache/2.2.17 mod_ssl/2.2.17 (Pass Phrase Dialog)
Server www.example.com:443 (RSA)
Enter pass phrase:
OK: Pass Phrase Dialog successful.
上面说过这个密码可以去除,这样就不需要每次开启 apache2 的时候都输入密码了,具体怎样做呢? 谷歌会告诉你。
扩展阅读
How To Generate SSL Key, CSR and Self Signed Certificate For Apache
本书简介:
- Linux 进阶技巧
- 巧妙的命令组合
- Bash 某些技巧
- 一共一百零一个(包括充数的)
- 最后有个奖励章(额外技巧)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论