Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx reverse proxy for node.js error Failed to lookup view "default" in views directory

Tags:

node.js

nginx

I am wants using Nginx as reverse proxy for my express.js app.

here is my nginx config :

server {
    listen 80;

    server_name  my server ip address;

    location / {
        proxy_pass http://myip:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

and its my app.js :

var express = require('express');
var mongoose = require('mongoose');
var app = express();

app.set('view engine' , 'ejs');
app.use(express.static('public'));

app.get('/song', function(req, res, next) {

   // my route
}

without nginx my app works very well but when i using nginx as reverse proxy and go to my song route node give me this error : Failed to lookup view "default" in views directory

i want know where i am wrong. thanks.

like image 363
alireza Avatar asked Nov 10 '22 15:11

alireza


1 Answers

I faced the same problem after configuring Nginx server. I found the solution.

The node couldn't able to find the path for the "views" folder in the project. so define the path.

var path = require("path");

app.set('view engine' , 'ejs');
app.set("views", path.join(__dirname, "views"));
like image 56
Surya Teja Avatar answered Nov 15 '22 05:11

Surya Teja