nginx+express,首页自动ajax请求返回502错误?
发布于 8 年前 作者 Web-Kevin 7377 次浏览 来自 问答

lz的环境是本地访问虚拟机 127.0.0.1:80 端口 用nginx代理express的127.0.0.1:3000 第一次nginx配置:


server {
        listen 80;
        server_name 127.0.0.1;

        access_log      /var/log/nginx/survey_access.log;
        error_log       /var/log/nginx/survey_error.log;

        location /public/ {
                root /home/kevin/nodeSrc/expressSrc/surveyProject;
        }
        location / {
                proxy_pass http://127.0.0.1:3000;
        }

}

但是首页加载时有个自动的ajax请求:

$('#tbl_list_index').bootstrapTable({
               url: '/JS_GetPage_Record', 
               method: 'post', 
               contentType: "application/x-www-form-urlencoded",
               striped: true, 
               cache: false, 
               pagination: true, 
               sortable: false, 
               sortOrder: "asc", 
               queryParams: function (params) {
                   return {
                       pageSize: params.limit,
                       pageIndex: params.offset
                   }
               },
               sidePagination: "server", 
               pageNumber: 1, 
               pageSize: 30,
               pageList: [30, 40, 50, 100], 
               strictSearch: true,
               clickToSelect: true, 
               //height: 600, 
               uniqueId: "Id", 
               cardView: false, 
               detailView: false, 
               smartDisplay: false,
               columns: [...] //省略
           });

请求回来一直是502: untitled3.png

这是nginx打的日志: untitled4.png

请各位指教,多谢

9 回复

没仔细看你的代码,但是ajax不能跨域。

express 服务有没有启动?先确认没有代理是否能正常访问。

@imhered 哦哦 页面上有个按钮是调用这个ajax的请求的,如果点击就可以正常访问

@Justin-lu 没有代理正常访问

nginx的upstream需要在配置一下

@TimothyJin 如何配置 能提醒一下么?

@imhered @Justin-lu @TimothyJin 问题解决了 是pm2的事情 在github pm2 上面的issue上有 是个bug

@Web-Kevin 嗨,你好,我刚刚试了下也是pm2的问题,但是解决办法是什么呢?虽然可以用forever替代pm2,但是,我比较想用pm2去管理啊。

@Web-Kevin ohoh,已经解决了,原来是pm2 --watch功能的问题

回到顶部