Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Last active October 23, 2024 12:32
Show Gist options
  • Save jpcaparas/ded09732f756db155e97216aa430d676 to your computer and use it in GitHub Desktop.
Save jpcaparas/ded09732f756db155e97216aa430d676 to your computer and use it in GitHub Desktop.
Make a node application work with PM2 & Laravel Forge
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/<your-site>/before/*;
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name <your-site>;
server_tokens off;
root /home/forge/<your-site>;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/<your-site>/1258011/server.crt;
ssl_certificate_key /etc/nginx/ssl/<your-site>/1258011/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/<your-site>/server/*;
location / {
expires $expires;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:3001; # set the address of the Node.js
}
access_log off;
error_log /var/log/nginx/<your-site>-error.log error;
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/<your-site>/after/*;
#!/bin/bash
cd /home/forge/<your-site>
git stash --include-untracked
git pull origin $FORGE_SITE_BRANCH
git stash clear
npm install
pm2 delete "$FORGE_SITE_ID" 2>&1 || :
pm2 start index.js --name "$FORGE_SITE_ID" -- --watch
@RemiC2care
Copy link

Hello,
Is it possible to also have a server.js exemple for this?
Thanks a lot.
Rémi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment