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

I want to use Nginx as a reverse proxy for my express.js application.

here is my nginx configuration:

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 application works very well, but when I use nginx as a reverse proxy and go to my songnode route , give me this error:Failed to lookup view "default" in views directory

I want to know where I am going wrong. thank.

+4
source share
1 answer

I had the same problem after setting up the Nginx server. I have found a solution.

node could not find the path to the "views" folder in the project. therefore, determine the path.

var path = require("path");

app.set('view engine' , 'ejs');
app.set("views", path.join(__dirname, "views"));
0
source

Source: https://habr.com/ru/post/1583939/


All Articles