Friday 2 June 2017

Nginx setup for a node server using angular cli

I am having issues with Nginx, Node Server and Express. I have deleted the default server block under /etc/nginx/sites-available and have added my own let's call it mikes-domain.com. I have copied the contents of the dist folder to /var/www/mikes-domain.com/html.

server {
listen 80 default_server;
root /var/www/html/mikes-domain.com/html
server_name: mikes-domain.com;
location /admin {
proxy_pass http://localhost:8082;
prody_http_version: 1.1;
proxy_set_header Upgrade $http_upgrade;
prody_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

Node and Express Server File

const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require ('body-parser');
const api = require('./server/routes/api');
const app = express;
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'node_modules')));
app.use(*/api', api);
app.set('trust proxy', true);
app.set('trust proxy', 'loopback');
const port = process.env.PORT || '8082';
http.createServer(app).listen(port);
console.log('Api listening on port ' + port);

When I visit mikes-domain.com/admin/ I am receiving this Cannot GET /admin/ but I am getting api works! which is what express should be displaying when I visit mikes-domain.com/admin/api/



via mkteagle

No comments:

Post a Comment