### ローカル環境
挙動テスト用に簡単にインストールしてコードを書きます。
$ node –version
v14.17.6
$ npm install express
1 2 3 4 5 6 7 | var express = require('express') var app = express() app.get('/', function(req, res){ res.send('hello world') }) app.listen(3000) |
http://192.168.34.10:3000/
### vps
$ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
$ sudo bash nodesource_setup.sh
$ sudo apt install nodejs
$ node -v
v14.18.1
$ cd /var/www/app
$ sudo npm install express
$ sudo touch app.js
$ sudo vi app.js // 上記と同じ
$ sudo vi /etc/apache2/sites-available/virtual.host.conf
Invalid command ‘ProxyPass’, perhaps misspe>
$ sudo a2enmod proxy_http
$ sudo systemctl restart apache2
$ node app.js
1 2 3 4 5 6 7 | var express = require('express') var app = express() app.get('/', function(req, res){ res.send('hello node') }) app.listen(3000) |
OK
$ sudo vi /etc/apache2/sites-available/virtual.host.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <VirtualHost *:80> DocumentRoot /var/www/app ServerName ****-test.site ServerAlias www.sample-test.site ProxyPass / http://***.**.**.***:3000 ProxyPassReverse / http://***.**.**.***:3000 # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/node ServerName ***.****-test.site # Other directives here </VirtualHost> |
こうすることで、一つのディレクトリはnodeで動かし、サブドメインの方はapacheで動かすということもできる
OKKKKKKKKKKK
さ、ラズパイやろう