将node.js作为代理运行时无法运行路由

时间:2014-03-31 16:54:20

标签: javascript node.js nginx proxy

我使用nginx作为服务器,而node.js作为代理(listen:3000),有一条名为user的路由,代码如下

exports.index = function (req, res){
  res.render('user', {
        id: req.params.id
    });
};

如果我运行http://domain.com:3000/user/1http://domain.com:3000/user/2 ...效果很好,但是如果我运行http://domain.com/user/1http://domain.com/user/2 ...它会显示错误'404',并且http://domain.com运行良好,那么如何修复呢?

nginx配置:

    listen 80;
    server_name domain.com www.domain.com;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    if ($host = 'www.domain.com' ) {
            rewrite ^/(.*)$  http://domain.com/$1   permanent;
    }


    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://127.0.0.1:3000/;
            proxy_redirect off;
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

0 个答案:

没有答案