【问题标题】:How do I install websocket-node on Ubuntu (Amazon EC2 instance)?如何在 Ubuntu(Amazon EC2 实例)上安装 websocket-node?
【发布时间】:2014-09-28 23:01:52
【问题描述】:

我一直在寻找,但我找到的解决方案都没有帮助。我唯一想做的就是

npm install websocket

我在此找到的大多数帖子都表明人们缺少 make、gcc、g++ 或 python,但我拥有所有这些。我的python是v2.7.6。

为了解决上述 npm 失败的问题,我已经做到了,

sudo npm --websocket:verbose --nodedir=/home/ubuntu/node install -g websocket

但是当我尝试时,我得到:

ubuntu@ip-172-31-20-33:~$ sudo npm --websocket:verbose --nodedir=/home/ubuntu/node install -g websocket

> websocket@1.0.8 install /usr/local/lib/node_modules/websocket
> node install.js

[websocket v1.0.8] Attempting to compile native extensions.
child_process: customFds option is deprecated, use stdio instead.
make: Entering directory `/usr/local/lib/node_modules/websocket/build'
  CXX(target) Release/obj.target/validation/src/validation.o
../src/validation.cc:117:34: error: ‘Arguments’ does not name a type
   static Handle<Value> New(const Arguments& args)
                                  ^
../src/validation.cc:117:45: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive]
   static Handle<Value> New(const Arguments& args)
                                             ^
../src/validation.cc:125:42: error: ‘Arguments’ does not name a type
   static Handle<Value> IsValidUTF8(const Arguments& args)
                                          ^
../src/validation.cc:125:53: error: ISO C++ forbids declaration of ‘args’ with no type [-fpermissive]
   static Handle<Value> IsValidUTF8(const Arguments& args)
                                                     ^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static void Validation::Initialize(v8::Handle<v8::Object>)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
   V8_INLINE HandleScope() {}
             ^
../src/validation.cc:108:17: error: within this context
     HandleScope scope;
                 ^
../src/validation.cc:109:58: error: no matching function for call to ‘v8::FunctionTemplate::New(v8::Handle<v8::Value> (&)(const int&))’
     Local<FunctionTemplate> t = FunctionTemplate::New(New);
                                                          ^
../src/validation.cc:109:58: note: candidate is:
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:3434:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
   static Local<FunctionTemplate> New(
                                  ^
/home/ubuntu/node/deps/v8/include/v8.h:3434:34: note:   no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const int&)’ to ‘v8::Isolate*’
../src/validation.cc:111:77: error: no matching function for call to ‘NODE_SET_METHOD(v8::Local<v8::Function>, const char [12], v8::Handle<v8::Value> (&)(const int&))’
     NODE_SET_METHOD(t->GetFunction(), "isValidUTF8", Validation::IsValidUTF8);
                                                                             ^
../src/validation.cc:111:77: note: candidate is:
In file included from ../src/validation.cc:9:0:
/home/ubuntu/node/src/node.h:211:13: note: template<class TypeName> void node::NODE_SET_METHOD(const TypeName&, const char*, v8::FunctionCallback)
 inline void NODE_SET_METHOD(const TypeName& recv,
             ^
/home/ubuntu/node/src/node.h:211:13: note:   template argument deduction/substitution failed:
../src/validation.cc:111:77: note:   cannot convert ‘Validation::IsValidUTF8’ (type ‘v8::Handle<v8::Value>(const int&)’) to type ‘v8::FunctionCallback {aka void (*)(const v8::FunctionCallbackInfo<v8::Value>&)}’
     NODE_SET_METHOD(t->GetFunction(), "isValidUTF8", Validation::IsValidUTF8);
                                                                             ^
../src/validation.cc:112:17: error: ‘NewSymbol’ is not a member of ‘v8::String’
     target->Set(String::NewSymbol("Validation"), t->GetFunction());
                 ^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static v8::Handle<v8::Value> Validation::New(const int&)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
   V8_INLINE HandleScope() {}
             ^
../src/validation.cc:119:17: error: within this context
     HandleScope scope;
                 ^
../src/validation.cc:121:27: error: request for member ‘This’ in ‘args’, which is of non-class type ‘const int’
     validation->Wrap(args.This());
                           ^
../src/validation.cc:122:17: error: request for member ‘This’ in ‘args’, which is of non-class type ‘const int’
     return args.This();
                 ^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h: In static member function ‘static v8::Handle<v8::Value> Validation::IsValidUTF8(const int&)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
   V8_INLINE HandleScope() {}
             ^
../src/validation.cc:127:17: error: within this context
     HandleScope scope;
                 ^
../src/validation.cc:128:36: error: invalid types ‘const int[int]’ for array subscript
     if (!Buffer::HasInstance(args[0])) {
                                    ^
../src/validation.cc:129:46: error: ‘New’ is not a member of ‘v8::String’
       return ThrowException(Exception::Error(String::New("First argument needs to be a buffer")));
                                              ^
../src/validation.cc:129:97: error: ‘ThrowException’ was not declared in this scope
       return ThrowException(Exception::Error(String::New("First argument needs to be a buffer")));
                                                                                                 ^
../src/validation.cc:131:38: error: invalid types ‘const int[int]’ for array subscript
     Local<Object> buffer_obj = args[0]->ToObject();
                                      ^
../src/validation.cc:134:67: error: ‘class v8::HandleScope’ has no member named ‘Close’
     return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
                                                                   ^
../src/validation.cc:134:78: error: too few arguments to function ‘v8::Handle<v8::Boolean> v8::True(v8::Isolate*)’
     return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
                                                                              ^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:6526:17: note: declared here
 Handle<Boolean> True(Isolate* isolate) {
                 ^
../src/validation.cc:134:89: error: ‘class v8::HandleScope’ has no member named ‘Close’
     return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
                                                                                         ^
../src/validation.cc:134:101: error: too few arguments to function ‘v8::Handle<v8::Boolean> v8::False(v8::Isolate*)’
     return is_valid_utf8(buffer_length, buffer_data) == 1 ? scope.Close(True()) : scope.Close(False());
                                                                                                     ^
In file included from ../src/validation.cc:8:0:
/home/ubuntu/node/deps/v8/include/v8.h:6535:17: note: declared here
 Handle<Boolean> False(Isolate* isolate) {
                 ^
/home/ubuntu/node/deps/v8/include/v8.h: In function ‘void init(v8::Handle<v8::Object>)’:
/home/ubuntu/node/deps/v8/include/v8.h:816:13: error: ‘v8::HandleScope::HandleScope()’ is protected
   V8_INLINE HandleScope() {}
             ^
../src/validation.cc:140:15: error: within this context
   HandleScope scope;
               ^
make: *** [Release/obj.target/validation/src/validation.o] Error 1
make: Leaving directory `/usr/local/lib/node_modules/websocket/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1059:12)
gyp ERR! System Linux 3.13.0-36-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/websocket
gyp ERR! node -v v0.13.0-pre
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok
[websocket v1.0.8]
    Native code compile failed!!
    Please note that this module DOES NOT REQUIRE the native components
    and will still work without them, though not quite as efficiently.

    On Windows, native extensions require Visual Studio and Python.
    On Unix, native extensions require Python, make and a C++ compiler.
    Start npm with --websocket:verbose to show compilation output (if any).
websocket@1.0.8 /usr/local/lib/node_modules/websocket

有人知道怎么回事吗?

我注意到 websocket-node 已经有一段时间没有更新了。我想知道 websocket-node 是否与 node v0.13.0-pre 不兼容?我什至应该使用 v0.13.0-pre 吗?

最终,我只想能够从同一端口上的同一 node.js 实例运行 http/https 和 ws/wss。 websocket-node seems able to handle fine,但不清楚如何处理 ws 模块(它适用于普通的旧 ws)。

任何关于如何使用 ws 的指示都和找出 websocket 出了什么问题一样好。

【问题讨论】:

  • 我假设您的意思是一个端口上的 https/wss 和另一个端口上的 http/ws? ws 模块不处理 SSL,但在节点应用程序中执行此操作没有多大意义。将 SSL 端口反向代理(使用 nginx、haproxy 等之一)到非安全端口并仅在非安全端口上运行节点可能是最简单的。如果听起来有帮助,我可以在答案中对此进行扩展。
  • 是的,这就是我的意思——一个端口上的 https/wss 和另一个端口上的 http/ws。但是为什么在一个应用程序中这样做没有意义呢?这看起来很简洁github.com/muaz-khan/WebRTC-Experiment/blob/master/…?
  • 哦,原来我看错了你的评论;是的,我喜欢反向代理的想法,并希望能解释我如何做到这一点。 :)
  • 我回答了一个关于 Nginx 反向代理的简短解释。希望对您有所帮助!

标签: node.js ubuntu amazon-ec2 websocket npm


【解决方案1】:

看来问题确实是与节点 v0.13.0-pre 不兼容。我得到了源并安装了节点 v0.10.32 然后做了

sudo npm --websocket:verbose --nodedir=/home/ubuntu/node-v0.10.32 install -g websocket

并且 websocket 安装正确。

【讨论】:

    【解决方案2】:

    我必须手动安装 node-gyp 才能使其他一些 npm install 正常工作。 我不记得我是否必须在全球范围内安装 node-gyp 但是...

    npm install -g node-gyp
    npm install websocket
    

    【讨论】:

      【解决方案3】:

      您可以使用反向代理,而不是依赖 Node.js 进行终止。这在许多方面是一个更简单的设置。如果您使用的是 Nginx,您需要如下配置文件:

      server {
        listen 443 ssl;
        server_name <hostname>;
        ssl_certificate <path>/<name>.crt;
        ssl_certificate_key <path>/<name>.key;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
      
        location / { 
          proxy_set_header Host $host;
          proxy_pass http://127.0.0.1:80;
        }
      }
      

      这将打开端口 443,对流向该端口的流量执行 SSL 终止,然后将流量转发到端口 80(您的 Node.js 应用将在此运行)。

      【讨论】:

        猜你喜欢
        • 2014-06-26
        • 1970-01-01
        • 2015-08-25
        • 2013-03-21
        • 2019-03-13
        • 2015-04-04
        • 1970-01-01
        • 2017-09-22
        • 2020-11-27
        相关资源
        最近更新 更多