NGINX 未找到 404 资源未加载

时间:2021-05-12 04:34:21

标签: node.js express nginx server

我使用 AWS EC2 来托管我的网页。我正在使用 Nodejs 服务器和 Nginx 进行反向代理。

节点服务器侦听端口 3000。当我转到 public_ip:3000 时,一切正常。如果我只访问 public_ip css javascript 并且所有其他资源未加载,链接也无法正常工作。 http://13.125.246.138:3000 http://13.125.246.138


const express = require('express')
const path = require ('path')
const app = new express();
const ejs = require('ejs');
const cors = require('cors');
var nodemailer = require("nodemailer");

app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.listen(3000,()=>{
    console.log('App listening 3000')
});
app.get('/', (req, res)=>{
    res.render('index');
})
app.get('/about', (req, res)=>{
    res.render('about');
})
app.get('/portfolio', (req, res)=>{
    res.render('portfolio');
})
app.get('/contact', (req, res)=>{
    res.render('contact');
})
app.get('/services', (req, res)=>{
    res.render('services');
})
              
  });
 server {
    listen 80 default_server;
    listen[::]:80 default_server;
    root var/www/html
    server_name _;
    location / {
    try_files $uri $uri/ =404;
    proxy_pass 0.0.0.0:3000/;
    } 

0 个答案:

没有答案