I got the error 404-not found for the styles.css using express and nginx.
My folder structure:
/client
deploy
/server
app.js
public
css
styles.css
test
abc.txt
views
index.html
In my app.js I use app.use(express.static(path.join(__dirname, "public"))).
The index route, app.use("/", require("./routes/root"))
In the root file, router.get("/", (req, res) => {return res.sendFile(path.join(__dirname, "..", "views", "index.html"))})
And in the index.html, <link rel="stylesheet" href="css/styles.css"/>
My nginx configuration:
server {
listen 443 ssl https;
server_name mydomain.com
root /var/www/mydomain.com/client/deploy;
}
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:3000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $http_host;
...
}
Everything seemed to work well but then I got the error 404 for styles.css. Url mydomain.com/api/styles.css not found. However, when I tried to create abc.txt and access it at mydomain.com/api/test/abc.txt, it worked. Access to mydomain.com/api/css is also routed to mydomain.com/css with a 404 error.
It confused me, I would appreciate any help you can give.
Thank your reading.