鍍金池/ 問答/Linux  HTML/ nodejs+express+nginx,由服務(wù)器向github發(fā)出GET請求,

nodejs+express+nginx,由服務(wù)器向github發(fā)出GET請求,訪問綁定該服務(wù)器的域名504錯誤

環(huán)境情況:
1.阿里云服務(wù)器
2.centos7系統(tǒng)
3.nodejs + express + nginx
以下是nginx的nginx.conf文件


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.4waifu.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://888.88.88.888:8080;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    server {
        listen       80;
        server_name  secret.4waifu.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://888.88.88.888:3000;
            index  index.html index.htm;
        }     
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

express的app.js

var express = require('express');
var app = express();
var http = require('http');
var qs = require('querystring');
var data = {
  client_id : '7aae72fc409dd7915676',
  scope: 'user%20admin:gpg_key',
  time: new Date().getTime()
};
var content = qs.stringify(data);
var options = {
  path: 'https://github.com/login/oauth/authorize',
  method: 'GET'
};
function httpReq (x) {
  http.request(options, function (res) {
    console.log(res)
    x(res.responseText);
  })
};
app.get('/', function (req, res) {
  console.log('1');
  httpReq(function (x) {
    res.send(x);
  });
});
var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;
});

目的:做一個用github賬號登錄的webapp。
1.webapp通知服務(wù)器需要github登錄
2.服務(wù)器向github發(fā)送GET
3.進入github賬號登錄頁面
4.github返回code并跳轉(zhuǎn)回服務(wù)器
5.拿返回的code和服務(wù)器上的client_secret再發(fā)送請求
6.github返回token
7.服務(wù)器把token發(fā)送給webapp

問題:
1.請問以上1-7的邏輯我的理解有錯嗎?
2.如果邏輯正確的話,我現(xiàn)在進入secret.4waifu.com就會出現(xiàn)504錯誤,是什么原因?qū)е碌哪兀渴且驗閚ginx把github的返回?fù)踝×藛幔?/p>

請各位大佬賜教!

回答
編輯回答
伐木累

504 是網(wǎng)關(guān)超時錯誤,就是nginx收到了客戶端瀏覽器的請求,要轉(zhuǎn)發(fā)到內(nèi)部web服務(wù)器時,內(nèi)部web服務(wù)器沒有響應(yīng)。于是等待一段時間后,nginx就會向客戶端瀏覽器返回"網(wǎng)關(guān)超時"錯誤。

上面代碼中

proxy_pass   http://888.88.88.888:3000;

這個地址是不符合ip地址的格式的。

2017年3月23日 09:44