繁体   English   中英

无法为Node.js应用正确配置Nginx

[英]Unable to configure Nginx correctly for Node.js app

我试图安装一个应用程序react.js并使用pm2包运行的服务器。

我的/etc/nginx/sites-available/default文件的内容是:

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;
    }
}

我的react服务器正在端口8080上运行,因为当我从服务器curl localhost:8080 ,我会得到适当的响应。 另外,使用curl localhost也可以得到正确的反应服务器的响应。

但是,当我在浏览器中访问my.domain.name时,我只是得到默认的nginx页面,表示已成功安装。

我在这里想念什么?

编辑:

添加了Reactjs应用的server.js文件:

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('在http:// localhost:8080 /收听); });

您的站点可用于nginx,但未启用。 因此,请尝试将您的配置(即/etc/nginx/sites-available/default移动或符号链接到/etc/nginx/sites-enabled/your.domain.name ,然后运行

/etc/init.d/nginx restart

接下来, 以下提示可能会进一步有助于解决节点内部的问题。

此外,您可以从以下配置中受益:

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

当放入sites-enabled我在DigitalOcean上的配置几乎相同,但是对于https,这很好用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM