1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu 20.04 Apache2 node.jsを動作させる(SSL対応)

Posted at

Kagoya.js VPS(Virtual Private Server)を利用し、Ubuntu 20.04をセットアップ。
更にApache2及び、Nodeをインストール。

# apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
node -v
v20.17.0

を確認。
更に
proxy及びproxy_http moduleを有効にする。

a2enmod proxy
a2enmod proxy_http

SSL対応は

certbot --apache -d www.example.com

/etc/apache2/sites-enabled/下にwww.example.com.confが生成されるので、

cd /etc/apache2/sites-enabled/
vi www.example.com.conf
<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   ServerName www.example.com
   ServerAlias www.example.com
   DocumentRoot /var/www/example
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
       ServerName www.example.com
       DocumentRoot /var/www/example
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.example.com
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
   ###ここから追加###
   SSLEngine on
   SSLProxyVerify none
   SSLProxyCheckPeerCN off
   SSLProxyCheckPeerName off
   SSLProxyCheckPeerExpire off
   SSLProxyEngine on
   ProxyRequests off
   ProxyPass / http://www.example.com:5007/
   ProxyPassReverse / http://www.example.com:5007/
   ###ここまで###
</VirtualHost>
</IfModule>

後は、node.jsのapp下で、server.jp等起動jsを指定してforeverにてnodeアプリをdaemon化し、常駐させます。

forever start server.js

最後にcertbot利用の場合の自動更新をcorntabに設定。

crontab -e
37      1    *       *       *       root    certbot renew
systemctl restart cron

以上、自分覚書として、投稿。
参考サイト:
https://qiita.com/someone-said-so/items/ef7ff1751afb72bb6d6e
https://medium.com/@ralphbetta/setup-node-js-servers-with-apache-on-ubuntu-vps-9b53e1f34c06

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?