vestacp-nodejs
vestacp-nodejs copied to clipboard
Connect() to unix app.sock failed (111: Connection refused)
Hello sir, thanks you for this template. But I have problem with my sock, the connection is refused
connect() to unix:/home/admin/web/mydomain/nodeapp/app.sock failed (111: Connection refused) while connecting to upstream
Server : Centos 7
I am try solving with CHMOD app.sock to 777, but isn't solve. Can you help me? Thanks!
You need to delete the app.sock every time before you start the node processe.
You need to delete the app.sock every time before you start the node processe.
Manual delete?
I am running using pm2, but not auto delete app.sock
This is my code
require('dotenv/config')
const path = require('path')
const bodyParser = require('body-parser')
const express = require('express')
const hbs = require('hbs')
const mysql = require('mysql')
const app = express()
const port = '/home/admin/web/domain.com/nodeapp/app.sock';
const hostname = 'domain.com';
const db = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE
});
db.connect((err) =>{
if(err) throw err;
console.log('Mysql connected...');
});
app.set('views', path.join(__dirname,'views'));
app.set('view engine', 'hbs');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use('/assets', express.static(__dirname + '/assets'));
var url = require('url')
function fullUrl(req){
return url.format({
protocol: req.protocol,
host: req.get('host'),
pathname: req.originalUrl
});
}
function urlHome(req){
return url.format({
protocol: req.protocol,
host: req.get('host')
});
}
hbs.registerHelper("prettifyDate", function(timestamp) {
return new Date(timestamp * 1000).toString('DD mm YYYY');
});
app.get('/', (req, res) => {
let sql = "SELECT * FROM tabel_post ORDER BY post_id DESC LIMIT 20";
let query = db.query(sql, (err, results) => {
if(err) throw err;
res.render('index', {
results: results,
title: process.env.HOME_TITLE,
description: process.env.HOME_DESC,
sitename: process.env.SITENAME,
sitename2: process.env.SITENAME.toUpperCase(),
cannonical: fullUrl(req),
urlHome: urlHome(req)
});
});
});
app.listen(port, hostname, () => {
console.log(`Example app listening at http://localhost:${port}`)
});
you need to set chmod 0777 of app.sock