使用Pug在实时服务器上获取404,但在本地主机上获取304

问题描述

所以,这很奇怪。我正在使用Express和Pug运行Nodejs应用程序。我的所有静态文件都位于“公共”文件夹中,而我的Pug文件都位于“视图”文件夹中。我将app.js文件设置为从Public文件夹中获取所有静态文件。我正在使用Nginx来处理服务器。

这是一个很奇怪的部分,当我使用AWS在Ubuntu实例上运行它时,我所有的js和css文件都得到了404。当我在本地计算机上运行它时,出现304错误,但所有内容都能正常工作。

任何想法我做错了什么?我将在下面显示一些代码

哈巴狗文件

  doctype html
    html
      head
        Meta(charset='utf-8')
        title Signature Pad
        Meta(name='description',content='Signature Pad - HTML5 canvas based smooth signature drawing using variable width spline interpolation.')
        Meta(name='viewport',content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no')
        Meta(name='apple-mobile-web-app-capable',content='yes')
        Meta(name='apple-mobile-web-app-status-bar-style',content='black')
        link(rel='stylesheet',href='stylesheets/signature-pad.css')
      #signature-pad.signature-pad
        .signature-pad--body
          canvas
        .signature-pad--footer
          div
            .description Sign Above
            .signature-pad--actions
              div
                button.button.clear(type='button',data-action='clear') Clear
                button.button(type='button',data-action='undo') Undo
              div
                form(action='',method='POST',onsubmit='completeAndRedirect();return false;')
                  label(for='fname') First name:
                  input#firstName(type='text',name='fname')
                  label(for='lname')          Last name:
                  input#lastName(type='text',name='lname')
                  br
                  br
                  label(for='company') Company:
                  input#company(type='text',name='company')
                  br
                  br
                  input.button.save(type='submit',value='Submit',data-action='save-svg')
      script(src='js/signature_pad.umd.js')
      script(src='js/app.js')

App.js文件

const express = require('express');
const path = require('path');
const NetSuiteOauth = require('netsuite-tba-oauth');
const bodyParser = require('body-parser');

const app = express();

//Parse incoming request
app.use(bodyParser.json());
//app.use(bodyParser.urlencoded({ extended: false }));

//View engine
app.set('views',path.join(__dirname,'views'));
app.set('view engine','pug');

//Static Files
app.use(express.static(__dirname + '/Public'));

app.get('/',(req,res,next)=> {
    return res.render('landing',{title: 'Home'})
});

app.get('/customer',next)=> {
    return res.render('signature',{title: 'Customer'})
});

app.get('/employee',{title: 'Employee'})
});

app.post('/customer',next)=>{    
    return res.render('entered',{title: 'Home'})
});

app.post('/employee',next)=>{    
       return res.render('entered',{title: 'Home'})
});

app.listen(8080);

文件夹结构

Image of File Structure

如果我不清楚,请让我知道,第一次在Stack上摆姿势

解决方法

在生产服务器的nginx上,您需要修改sites_available文件,以使其默认指向静态文件夹。

server {
root /www/data;

location / {
}
.....
}

请检查提供静态文件夹static nginx的附加链接