Centos7 配置 Apache + Node.js with SSL

之前一直用的是LNMP,配合Wordpress效果还不错。最近自己也写了不少Javascript,想了想尝试换成Node.JS加Ghost博客。考虑到Node本身的局限,以及之后有可能架设多个网站,用Apache做反向代理(当然Nginx也可以)。

在Centos下安装Apache

yum -y update
yum -y install httpd
systemctl enable httpd

可以用

apachectl -V

命令看到当前安装的版本。这里安装的是Apache/2.4.6。

添加配置文件

默认的配置文件目录为:
/etc/httpd/conf.d

在目录下新建yuyii.conf并添加:

其中SSLCertificateFileSSLCertificateKeyFileSSLCertificateChainFile是从SSL证书供应商获得的。自己用的是免费的Let's Encrypt, 可以参照安装说明获取相应的证书。申请SSL证书时注意填好别名。
另外还有两个Redirect的配置,注意相应的SSL证书也要设置。

第一次配置出现了证书显示自签发的问题,一开始以为申请的SSL证书有问题,后来发现是自己写的VirtualHost没有对应正确的域名,被转到了ssl.conf的default VirtualHost配置下...

配置Node.js服务

添加Systemd配置文件:/usr/lib/systemd/system/node-yuyii.service

[Unit]
Description=Node js yuyii server
After=network.target

[Service]
PermissionsStartOnly=true
ExecStart=/usr/bin/npm start --production
WorkingDirectory=/home/nodejs/yuyii
Restart=on-abort
User=nodejs
Group=nodejs
UMask=0027

[Install]
WantedBy=multi-user.target

其中WorkingDirectory就是Ghost所在目录。最后别忘了设置服务自启动:

systemctl enable node-yuyii
comments powered by Disqus