【问题标题】:hosting nodejs applications using nginx in ec2 AWS在 ec2 AWS 中使用 nginx 托管 nodejs 应用程序
【发布时间】:2018-06-29 15:55:19
【问题描述】:

/etc/nginx/nginx.conf 文件 在 http 部分,给出以下信息。

包括/etc/nginx/conf.d/*.conf;

/etc/nginx/conf.d/myapp.conf文件内容

server {
        listen 80;
        listen [::]:80;
        server_name _;
        index index.html index.htm;


        location  / {

               proxy_pass 'http://XXXXX:3005/';
        }

         location /admin/ {

                proxy_pass 'http://XXXX:3000/';
        }

}

http://XXXX 正在重定向到主页。 http://xxxxx/admin/ 没有重定向。相反,它在 chrome 控制台中抛出错误。

error image

同一站点运行良好http://xxxx:3000 它运行良好。没有问题。

我还缺少什么?

注意:操作系统是 Amazon Linux,我已经使用示例帮助世界节点 js 程序测试了相同的配置,它工作正常。

【问题讨论】:

    标签: node.js amazon-web-services nginx nginx-location nginx-reverse-proxy


    【解决方案1】:

    确保你的路由是正确的,并且你已经在配置后重启了nginx。

    试试下面的配置:

    server {
        listen 80;
    
        server_name example.com;
    
        location / {
            proxy_pass http://APP_PRIVATE_IP_ADDRESS:3005;
            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 /admin {
            proxy_pass http://APP_PRIVATE_IP_ADDRESS:3000;
            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;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-22
      • 2020-08-28
      • 2016-04-14
      • 1970-01-01
      • 2012-10-28
      • 2011-11-16
      • 2014-12-24
      • 2020-04-25
      • 2016-03-15
      相关资源
      最近更新 更多