Search code examples
angularjsurlnginxprettify

nginx, express, angular URL redirect loop


Not sure how to describe this problem.

localhost:8000/home on my app works fine. However when I deploy to my digitalocean server and go to www.domain.com/home it looks like the url flickers and redirecting itself between www.domain.com/home and www.domain.com really fast to the point where it crashes

I'm thinking it has something to do with me prettifying my angular urls and my nginx configuration and maybe my node?

Here's my nginx config

server{
  listen 80;

  server_name mydomain.com www.mydomain.com;

  location / {
      proxy_pass http://127.0.0.1:8000;
      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;
  }
}

My angular routing page

    $urlRouterProvider.when('/', 'home');
    $urlRouterProvider.otherwise('404');

    $stateProvider
    .state('home', {
        url: "/home",
        templateUrl: "app/home.html",
        controller: "HomeCtrl",
        controllerAs: "home",
        data: {
            contentPages: 1
        }
    });

    $locationProvider.html5Mode(true);

and my server.js file

var express = require('express');
var app = express();
var bodyParser = require('body-parser');



var server = app.listen(8000, function(){
    console.log('The dagger flies at 8000');
});

var io = require('socket.io').listen(server);

require('./sockets')(io);

// Local ENV ======================================================================


var env = require('./config/config.json')[app.get('env')];


app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

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

app.get('/*', function(req, res, next) {
    res.sendFile('index.html', { root: 'public' });
});

Any ideas?


Solution

  • Sigh, turns out I was getting an error in console I didn't catch

    /code Error: EACCES: permission denied, open 'cratedump.log' at Error (native)

    I needed to sudo chmod 777 this file...

    Anyways, it works now.