In short: I have the same problem as previously asked and answered within this question(How to setup routes with Express and NGINX?) although my files look slightly different since I'm using HTTPS and I never made use of try_files
.
The normal root link works (my.website.org), but when I navigate to (my.website.com/login), I get a 404 from NGINX
The sites by themselves all work perfectly fine (also when I switch out the index for the login), but as soon as I am not accessing the root link i receive the 404 :(. I already tried a couple of suggested solutions but somehow couldn't make any work for me. Maybe someone on here has a suggestion regarding my setup.
Filestructure of my project:
my
| - public
| - views
| | - index.pug
| L - login.pug
| - app.js
L - package.json
First up my app.js file:
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
// Load View Engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// Home Route
app.get('/', function(req, res){res.render('index');});
// Login Route
app.get('/login', function(req, res){res.render('login');});
// Start Server
app.listen(3000, function(){console.log('Server started on port 3000...');});
Next my NGINX Configuration:
server {
listen 80;
server_name my.website.org;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name my.website.org;
access_log /var/log/nginx/my.access.log;
error_log /var/log/nginx/my.error.log;
location = / {
proxy_redirect off;
proxy_pass http://localhost: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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /var/www/my/public;
access_log off;
expires max;
}
ssl_certificate /myfullchain.pem;
ssl_certificate_key /mykey.pem;
}