Skip to content

Commit

Permalink
Update some journey . .
Browse files Browse the repository at this point in the history
  • Loading branch information
krlan2789 committed Jun 11, 2024
1 parent d97ade3 commit fbc6eef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
6 changes: 3 additions & 3 deletions public/data_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@
},
{
"id": "2",
"title": "Node.JS WebSocket Service on VPS",
"description": "Setup Node.JS WebSocket Service with Subdomain on VPS",
"title": "WebSocket Service on VPS",
"description": "Setup Websocket Service (Node.js) and Subdomain on VPS",
"source": {
"url": "/journey/Setup Node.JS WebSocket Service with Subdomain on VPS.md",
"url": "/journey/Setup Websocket Service (Node.js) and Subdomain on VPS.md",
"type": "local",
"images": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
# Setup Node.JS WebSocket Service with Subdomain on VPS
# Setup Websocket Service (Node.js) and Subdomain on VPS

Owner: Erlan Kurnia
Created time: May 1, 2024 2:11 AM

> Assume the subdomain to be used is websocket.krlan2789.com and the VPS IP is 10.0.27.89
>
>
1. Add DNS Record for subdomain :



| Type | Name | Points to | TTL |
| ---- | --------- | ---------- | ----- |
| A | websocket | 10.0.27.89 | 14400 |
2. Create a certificate for subdomain using certbot :

```bash
sudo certbot certonly --webroot -w /root/repositories/WebSocket-Service -d websocket.krlan2789.com
```

3. Activate the required module :

```bash
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel
```

4. Create Apache config for subdomain :

```ruby
<VirtualHost *:80>
ServerName websocket.krlan2789.com
Redirect permanent / https://websocket.krlan2789.com
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName websocket.krlan2789.com
ProxyPreserveHost On
RewriteEngine On
# Upgrade connections to WebSockets
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:8765/$1 [P,L]
Expand All @@ -50,49 +49,49 @@ Created time: May 1, 2024 2:11 AM
# Everything else forwards as HTTP to the node app.
ProxyPass / http://localhost:8765/
ProxyPassReverse / http://localhost:8765/
DocumentRoot /root/repositories/WebSocket-Service
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
# SSL Certificate file location
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/websocket.krlan2789.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/websocket.krlan2789.com/privkey.pem
</VirtualHost>
</IfModule>
```

5. Verify to ensure the Apache config file is correct :

```bash
sudo apache2ctl configtest
```

6. Enable subdomain Apache config :

```bash
sudo a2ensite websocket.krlan2789.com.conf
```

7. Restart/reload Apache service :

```bash
sudo service apache2 start
*OR*
sudo systemctl reload apache2
```

8. Check the Apache service is running without any errors :

```bash
systemctl status apache2.service
```

9. Run a Node.js app using PM2 to automatically run it when the application crashes until the system reboots/restarts (make sure the system has node and NPM installed beforehand) :

```bash
npm i -g pm2
pm2 start /root/repositories/WebSocket-Service/app.js --name 'Websocket-Service-App'
Expand Down

0 comments on commit fbc6eef

Please sign in to comment.