0
0

More than 1 year has passed since last update.

nodeアプリをさくらのVPS で動かす

Posted at

忘備録です。

OSインストール

「スタートアップスクリプト」 ・・・ なんか色々機能があって便利だった。必要なものを入れる。
「パケットフィルター設定」 ・・・ firewallの代わり? 必要なポートは開けておく
「サーバーへのSSHキー登録」

初期設定

ssh root@xxx.xxx.xxx.xxx
yum update
adduser 〇〇〇〇
passwd 〇〇〇〇
cd /etc/ssh
cp sshd_config sshd_config.old
vim sshd_config

↓ここを変える

sshd_config
PermitRootLogin no
systemctl restart sshd.service

環境設定

yum install httpd
systemctl start httpd
//ブラウザで開いてみる
systemctl enable httpd
cd /var/www
chown apache:〇〇〇〇 html
chmod 775 html
//htmlファイル置いてブラウザで開いてみる
cd
wget https://www.python.org/ftp/python/3.x.y/Python-3.x.y.tgz
tar xzf Python-3.x.y.tgz
cd Python-3.x.y
./configure
make
make install
python3 –version
//終わったらダウンロードしたファイルとかは消しておく
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo yum -y install --enablerepo=remi,remi-php81 php php-fpm php-devel php-cli php-common php-mbstring php-mysqlnd php-pear php-tcpdf php-mcryptphp-process php-pdo php-bcmath php-xml php-gd php-recode php-pecl-msgpack php-pecl-memcached
systemctl restart httpd
yum install mariadb-server
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
//パスワードとかを設定しておく
cd /etc
cp php.ini php.ini.old
vim php.ini

post_max_size と upload_max_filesize を 128M にしておく

SSL設定

スタートアップスクリプトがあったみたいだけど気付かなかった。
上記の記事を参考にドメインのネームサーバーの設定をしておく

cd /etc/httpd/conf
vim httpd.conf

一番下に追加しておく

httpd.conf
IncludeOptional domains/*.conf

domainsディレクトリに適当な名前の.confファイルを作り、ドメインの設定を書いておく

〇〇.conf
<VirtualHost *:80>
	ServerName exsample.com
	DocumentRoot /var/www/html/
</VirtualHost>
systemctl restart httpd

しばらく時間を置いてみて、ドメインが表示されるか確認する。

yum install mod_ssl
yum install certbot python2-certbot-apache
certbot --apache -d example.com
systemctl restart httpd

cronに設定しておく

cron
0 3 *  *  * root /usr/bin/certbot renew

httpsで確認する。

nodeアプリ

curl -L git.io/nodebrew | perl - setup
vim .bash_profile
.bash_profile
export PATH=$HOME/.nodebrew/current/bin:$PATH
source ~/.bash_profile
nodebrew -v
nodebrew ls
nodebrew use [VERSION]
cd /var/www/html
npm init
npm install express --save
npm install -g forever --save
//もしtypescriptで作るなら
npm install --save typescript ts-node

処理するapp.tsを作成したら

npx tsc
cd dist
forever start app.js

停止するときは

forever stop app.js

ーーーーーーーーーーーーーーーーーーーーーーーーー
参考

0
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
0
0