带有Web-stomp,nginx和SSL的RabbitMq

时间:2019-05-22 19:45:42

标签: nginx rabbitmq

我现在快要死了。我只想为RabbitMq使用独立服务器,并希望连接所有类型的客户端。

这是到目前为止我得到的:

Nginx-Conf:

server {
  ssl_certificate     /etc/letsencrypt/live/sub.domain.de/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sub.domain.de/privkey.pem;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;
  listen              443 ssl;
  listen              [::]:443;
  server_name         sub.domain.de;

  client_max_body_size 20M;

  root    /var/www/html/projects/domain/sub/public;
  index   index.php index.html index.htm index.nginx-debian.html;

  location ~* /stomp/(.*?) {
    add_header 'Access-Control-Allow-Origin' "$http_origin" always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    proxy_pass http://127.0.0.1:15674/stomp/$1?$query_string;
    proxy_buffering                    off;
    proxy_set_header Host              $http_host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

rabbitMq Conf:

[
  {rabbitmq_web_stomp,
    [
      {use_http_auth, true},
      {proxy_protocol, true},
      {ssl_config, [
        {port, 15671},
        {backlog, 1024},
        {certfile, "/etc/letsencrypt/live/sub.domain.de/cert.pem"},
        {keyfile, "/etc/letsencrypt/live/sub.domain.de/privkey.pem"},
        {cacertfile, "/etc/letsencrypt/live/sub.domain.de/fullchain.pem"}
      ]}
    ]
  },
  {rabbit,
    [
      {tcp_listeners, [5682]},
      {ssl_options, [
        {certfile, "/etc/letsencrypt/live/sub.domain.de/cert.pem"},
        {keyfile, "/etc/letsencrypt/live/sub.domain.de/privkey.pem"},
        {cacertfile, "/etc/letsencrypt/live/sub.domain.de/fullchain.pem"},
        {verify,     verify_peer},
        {fail_if_no_peer_cert, false}
      ]},
      {loopback_users, []}
    ]
  },
  {rabbitmq_management,
    [
      {listener, [
        {port, 15672},
        {ssl, true},
        {ssl_opts, [
          {certfile, "/etc/letsencrypt/live/sub.domain.de/cert.pem"},
          {keyfile, "/etc/letsencrypt/live/sub.domain.de/privkey.pem"},
          {cacertfile, "/etc/letsencrypt/live/sub.domain.de/fullchain.pem"}
        ]}
      ]}
    ]
  }
].

代码:

var ws = new SockJS('https://sub.domain.de/stomp');
client = Stomp.over(ws);

在服务器内,我能够发布消息,所以我假设RabbitMq正在运行。但是使用JS,我会遇到以下错误:

sockjs.min.js:3 WebSocket connection to 'wss://sub.domain.de/stomp/298/1lartzyy/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200
sockjs.min.js:2 POST https://sub.domain.de/stomp/298/ha0birjx/xhr_streaming?t=1558553747301 405 (Method Not Allowed)
(index):1 EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.
sockjs.min.js:2 POST https://sub.domain.de/stomp/298/1pnvlsvc/xhr?t=1558553750167 405 (Method Not Allowed)
jsonp?c=_jp.axxled1:1 Uncaught SyntaxError: Unexpected identifier
stomp.min.js:145 Whoops! Lost connection to https://sub.domain.de/stomp
wsController.js:46 >WsController:on_error<  Whoops! Lost connection to https://sub.domain.de/stomp

因此,在接下来的过程中,我可能需要一点帮助。

谢谢

0 个答案:

没有答案