Ubuntu + Apache + SSL + 数字证书(Apache配置)Ubuntu操作系统下使用Apache来配置SSL和数字证书
这个标题就是它的原样。
Ubuntu + Apache + SSL + 数字证书 (1.Apache版本)
Ubuntu + Apache + SSL + 数字证书 (2.SSL版本)
Ubuntu + Apache + SSL + 数字证书 (3.数字证书版本)
我会几乎实时记录工作的进展。之后整理可能没什么希望,所以就不弄了。
工作日期:2020年6月
参考书
《深入浅出Ubuntu服务器》 翔泳社
在进行的过程中,我决定参考Qiita前辈们的文章继续进行。
环境:我使用了樱花VPS V5(操作系统:Ubuntu 18.04 amd64)。关于DNS服务器的事情,我委托给了樱花先生。
初心:
因为我之前一直使用V4(操作系统:CentOS7 x86_64),所以对于V5来说有很多不熟悉的地方,而且我只在Apache上进行了简单的配置,没有接触过其他复杂的功能,所以我会在摸索中不断锻炼自己。
更新包裹信息索引。
$ sudo apt update
我們將更新系統。
$ sudo apt upgrade
在开始工作之前,我会先检查开放的端口。
$ ss -atl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.53%lo:domain 0.0.0.0:*
LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
LISTEN 0 128 [::]:ssh [::]:*
我们将安装Apache。
$ sudo apt install apache2
我們將檢查已打開的端口。HTTP 已經打開了。
$ ss -atl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.53%lo:domain 0.0.0.0:*
LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
LISTEN 0 128 *:http *:*
LISTEN 0 128 [::]:ssh [::]:*
在/etc下面生成了与Apache相关的配置文件。
$ ls /etc/apache2
apache2.conf conf-enabled magic mods-enabled sites-available
conf-available envvars mods-available ports.conf sites-enabled
在/var目录下生成了默认的index.html文件。
$ cd /var/www/html
$ ls
index.html
我会确认一下 Apache 是否正在运行。
HTML 的长源码被输出,并以 success 结束。
$ curl localhost && echo success || echo failed
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
(中略)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Apache2 Ubuntu Default Page: It works</title>
(中略)
</head>
<body>
(中略)
<div class="section_header section_header_red">
<div id="about"></div>
It works!
</div>
(中略)
</body>
</html>
success
为了让您可以从网络浏览器访问,我们需要更改防火墙的设置。
$ sudo ufw allow http
Rules updated
Rules updated (v6)
确认外部的80号端口已经打开。
$ sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] 80/tcp ALLOW IN Anywhere
[ 2] 22/tcp LIMIT IN Anywhere
[ 3] 80/tcp (v6) ALLOW IN Anywhere (v6)
[ 4] 22/tcp (v6) LIMIT IN Anywhere (v6)

在系统启动时,让Apache也自动启动。
$ sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
在这里,我会查看 /etc/apache2/apache2.conf 文件。
$ cat apache2.conf
(前略)
#Mutex file:${APACHE_LOCK_DIR} default
(中略)
DefaultRuntimeDir ${APACHE_RUN_DIR}
(中略)
PidFile ${APACHE_PID_FILE}
(中略)
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
(中略)
ErrorLog ${APACHE_LOG_DIR}/error.log
(後略)
上述的 ${APACHE_*} 是什么,根据 /etc/apache2/envvars 中的描述,我会备份一份记录。
APACHE_PID_FILE=/var/run/apache2(SUFFIX)/apache2.pid
APACHE_RUN_DIR=/var/run/apache2(SUFFIX)
APACHE_LOCK_DIR=/var/lock/apache2(SUFFIX)
APACHE_LOG_DIR=/var/log/apache2(SUFFIX)
APACHE_RUN_USER=www-data
APACHE_RUN_GROUP=www-data
$ cat /etc/apache2/envvars
# envvars - default environment variables for apache2ctl
# this won't be correct after changing uid
unset HOME
# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
SUFFIX=
fi
# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2$SUFFIX/apache2.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale
export LANG
## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'
## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'
## If you would like to pass arguments to the web server, add them below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''
## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web server modules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1
继续进行Ubuntu + Apache + SSL + 数字证书 (2.SSL篇)
继续进行Ubuntu + Apache + SSL + 数字证书 (3.数字证书篇)