我正在尝试从一台机器连接到另一台安装了 RabbitMQ 的远程服务器。RabbitMQ 在本地运行良好,但是当我从另一台机器连接到它时,会发生错误:
root@xxx:~# python3 rabbitmq.py
Traceback (most recent call last):
File "rabbitmq.py", line 8, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(parameters))
File "/usr/local/lib/python3.4/dist-packages/pika/connection.py", line 652, in __init__
self.host = host
File "/usr/local/lib/python3.4/dist-packages/pika/connection.py", line 392, in host
(value,))
TypeError: host must be a str or unicode str, but got <ConnectionParameters host=111.111.111.111 port=5672 virtual_host=product ssl=False>
root@xxx:~#
Run Code Online (Sandbox Code Playgroud)
TypeError: host must be a str or unicode str, but got ConnectionParameters host=111.111.111.111 port=5672 virtual_host=product ssl=False
其他远程机器上的 Python 代码:
import pika
credentials = pika.PlainCredentials(username='remoteuser', password='mypassword')
parameters …Run Code Online (Sandbox Code Playgroud) 我正在学习 NodeJs 的 NestJs 框架,以使用 Vue 和后端部分创建带有前端的网站。所有组件都在这一台服务器上:Nginx、前端和后端(本文对我有帮助https://scotch.io/tutorials/building-a-modern-app-using-nestjs-mongodb-and-vuejs)一切正常如果我通过 IP 地址连接到网站。然后我需要将其迁移到具有 SSL 的真实站点以进行 HTTPS 访问。这是一个问题。
在前端,我将文件 /nestjs-frontend/src/helper.js 更改为:
// ./src/helper.js
export const server = {
baseURL: 'https://my_site.ru:3000'
}
Run Code Online (Sandbox Code Playgroud)
注意!端口3000
问题出在从主域https://my_site.com到内部 API 路径https://my_site.com:3000的访问中
请帮我解决这个问题。
我的 Nginx 配置是:
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name my_site.com www.my_site.com;
location / {
#proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
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 https;
proxy_set_header SSL_PROTOCOL $ssl_protocol;
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; …Run Code Online (Sandbox Code Playgroud) 我尝试在 Python 3.4 (Windows 7) 中使用 WebSockets 这是一个测试代码:
from twisted.internet import reactor
from autobahn.twisted.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
import json
class ClientProtocol(WebSocketClientProtocol):
def onConnect(self, response):
print("Server connected: {0}".format(response.peer))
def initMessage(self):
message_data = [{"type": "subscribe", "product_id": "BTC-USD"}]
message_json = json.dumps(message_data)
print("sendMessage: " + message_json)
self.sendMessage(message_json)
def onOpen(self):
print("onOpen calls initMessage()")
self.initMessage()
def onMessage(self, msg, binary):
print("Got echo: " + msg)
def onClose(self, wasClean, code, reason):
print("WebSocket connection closed: {0}".format(reason))
if __name__ == '__main__':
factory = WebSocketClientFactory("wss://ws-feed.exchange.coinbase.com")
factory.protocol = ClientProtocol
connectWS(factory)
reactor.run() …Run Code Online (Sandbox Code Playgroud)