如何检查请求来源

时间:2014-06-25 06:13:54

标签: node.js nginx

我有以下节点服务器在3000端口运行。

//File1.js
var express = require("express");
var app = express();
//app.use(express.bodyParser());
app.get('/samp', function(req, res){
    console.log(req)
    res.send('hello world');
});
app.listen(3000);

我在nginx中配置了相同的服务器。

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;
    upstream node_stream {
        server localhost:3000;
        }
    server {
        listen       4000;
        server_name  <some external server IP>;
        root        /usr/local/nginx/html;
        index       index.html;
        underscores_in_headers on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
         proxy_pass http://node_stream;
            root   html;
            index  index.html index.htm;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503         http_504;
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        Host            $host;
            }
    }
}   

当我点击http://<some external server IP>:4000/时,它会间接获得http://localhost:3000/samp的回复。在我的File1.js中如何检查请求是否来自nginx服务器?我需要在nginx cong文件中设置一些头文件吗?

0 个答案:

没有答案