如何在Ubuntu上安装websocket节点(AmazonEC2实例)



我已经到处找了,但我找到的解决方案都没有帮助。我想做的就是

npm安装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节点已经更新了一段时间。我想知道websocket节点是否与node v0.13.0-pre不兼容?我应该使用v0.13.0-pre吗?

最终,我只想能够运行http/https&来自同一端口上的同一node.js实例的ws/wss。websocket节点似乎能够很好地处理,但不清楚如何处理ws模块(它只适用于普通的旧ws)。

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

问题似乎确实与节点v0.13.0-pre不兼容。我获得了源代码并安装了节点v0.10.32,然后进行了

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

和websocket安装正确。

我不得不手动安装node-gyp,以使其他一些npm安装正常工作。我记不起我是否必须在全局范围内安装node-gyp,但。。。

npm install -g node-gyp
npm install websocket

您可以使用反向代理,而不是依赖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应用程序将在那里运行)。

相关内容

  • 没有找到相关文章

最新更新