I have a node app that works locally and uses Express for routing. I have tried to set this up on digital ocean using their guide. I can see the home page of my app when I navigate to /, but I cannot access any inner pages.
To debug I stopped the app running through pm2 and simply ran it by calling 'node app.js' in the terminal so that I can see the console log messages.
I put comments on Express routes for testing:
app.get('/', function (req, res) {
console.log('/ route requested');
if (req.isAuthenticated()) {
res.render('home',
{
user: req.user
});
} else {
res.render('home',
{
user: null
});
}
});
app.get('/signup', function (req, res) {
console.log('/signup route requested');
res.render('signup');
});
When I request '/' the console log message is printed. However trying to visit '/signup' nothing is shown in the terminal. I am taken to a default 404 page (nginx/1.10.0 (Ubuntu).
I have tried to set up Nginx as a reverse proxy as detailed here. Here is my nginx configuration from etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
proxy_pass http://localhost:2000;
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;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
Also the index page isn't loading resources from my public directory, such as styles.
I would appreciate any help trying to get the Express routes and resources to load on the remote server. Please let me know if their is further information that would be helpful for debugging.