skip to Main Content

From the research I’ve done I can see you need to edit a file in nginx and change a location so static files can be served but I don’t quite understand how to do this so my css cannot be found, I got the file open and it looks like this:
Nginx config file.
I don’t really know what to do from here as the other similar questions seem to have very specific or complicated answers.

My html to link the css:

<link rel="stylesheet" href="/css/index.css">

my node server:

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

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

app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname + '/templates/index.html'));
});


app.listen(8080);

My folder layout:
folder layout

2

Answers


  1. I had a similar issue and I just resolved it by restructuring my folders.
    Check the path in the error you see via dev tools and see if it matches your folder structure.

    Another resolve might be in your nginx configuration. I added

    include /etc/nginx/mime.types;

    in the server directive block, though the folder restructure is what fixed my problem.

    Login or Signup to reply.
  2. Not sure if this applies to every situation, however:
    When using an ubuntu server to host a nodejs / express website, nginx isn’t needed at all. Simply make the express server run on port 80, the web traffic port, disable ufw firewall to allow all traffic, set up cloudfare or any other ssl that allows http and https to act as a new firewall. Once the server is running on port 80 and your domain is set up correctly with the right nameservers etc, it should all be working an then optionally you can use pm2 to host mutliple things or still have access to server while website is running.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search