【问题标题】:Node.js is not working in Reactjs app - nginxNode.js 在 Reactjs 应用程序中不起作用 - nginx
【发布时间】:2019-11-21 11:25:27
【问题描述】:

本地一切正常,现在我试图让节点正常工作,但我不能

这是我的 nginx 配置:

server {
  listen       80;
  server_name  54.38.184.210;

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

  location / {
    root /root/site/public;
    try_files $uri /index.html;
}

}

http://54.38.184.210/ 我运行 - npm run build,然后我将所有 dist 文件公开,静态内容正在运行,我可以看到整个网站,但后端无法正常工作,我使用“node index.js”启动我的服务器

也许我做错了什么,请帮助我!

【问题讨论】:

  • 您是否在不同的端口上启动了服务器端和客户端?一切都好吗?

标签: node.js reactjs nginx debian


【解决方案1】:

请试试这个,

server {
         listen 443 ssl;
         server_name 54.38.184.210;
         ssl_certificate {your path to .crt file}/api.crt;
         ssl_certificate_key {your path to .rsa file}/api.rsa;
            location / {
                        proxy_pass 54.38.184.210: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;
                     }
        }

"service nginx restart" 重启你的后端 nginx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-25
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    相关资源
    最近更新 更多