0

I am trying to install a react.js app and using pm2 package for running the server.

My /etc/nginx/sites-available/default file's contents are:

server {
    listen 80;

    server_name my.domain.name;

    location / {
        proxy_pass http://127.0.0.1:8080;
        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 react server is running on port 8080, since when I do curl localhost:8080 from the server, I get the appropriate response. Also, with curl localhost also I get the correct react server's response.

However, when I visit my.domain.name in the browser, I just get the default nginx page saying it's successfully installed.

What am I missing here?

Edit:

Added Reactjs app's server.js file:

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
  publicPath: config.output.publicPath,
  hot: true,
  historyApiFallback: true
}).listen(8080, 'localhost', function (err, result) {
  if (err) {
    return console.log(err);
  }

console.log('Listening at http://localhost:8080/'); });

tekina
  • 571
  • 10
  • 21

1 Answers1

0

Your site is available to nginx, but not enabled. So try moving or sym-linking your configuration, i.e. /etc/nginx/sites-available/default, to e.g. /etc/nginx/sites-enabled/your.domain.name and then running

/etc/init.d/nginx restart

Next, the following hint may help further with respect to issues internal to node.

Furthermore, you might benefit from adding the following to your config:

proxy_redirect  http://localhost:8080 http://your.domain.name;

When put into sites-enabled my config on DigitalOcean is pretty much the same, but for https, which works just fine.

Community
  • 1
  • 1
Oleg Sklyar
  • 9,834
  • 6
  • 39
  • 62
  • I have already sym-linked my configuration file. Adding `proxy_redirect` doesn't seem to help as well. – tekina Aug 21 '16 at 22:57
  • If you have sym-linked the config then please update your question again as the problem lies in a small detail somewhere: given the content and the location of the file this should work. But do try leaving out 'localhost' in the server config, which will make it listen on 0.0.0.0. If this works, restrict it to 127.0.0.1 and try again – Oleg Sklyar Aug 22 '16 at 07:27
  • Check the link I added to the answer, essentially it is about the same what I put in the comment: try skipping the hostname in the node http server listen method. – Oleg Sklyar Aug 22 '16 at 07:31