首頁  >  問答  >  主體

express - nginx設定後存取不到主動ajax請求?

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

}

訪問首頁127.0.0.1 能成功顯示,但在首頁有個自動的ajax請求是127.0.0.1/JS_GetPage_Record 這個請求一直502,不通過nginx反代都正常如果手動去點按鈕觸發這個按鈕返回是正常的


以下為解決方法

html

$('#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: [...] //省略
            });

這是html裡ajax打開首頁自動請求的語句,查看訊息 X-Powered-By:nginx1.6.2 一看就是還沒到express裡面,所以nginx配置加上,成功請求!

 location /JS_GetPage_Record {
                proxy_pass http://127.0.0.1:3000/JS_GetPage_Record;
        }

但是不理解為何,主動請求nginx不繼續往下請求,難道每個自動請求都要寫入nginx配置?


今天一測 又不好使了

ringa_leeringa_lee2713 天前469

全部回覆(1)我來回復

  • 某草草

    某草草2017-05-16 17:18:49

    直接訪問 http://127.0.0.1/JS_GetPage_Record 出來什麼

    回覆
    0
  • 取消回覆