聊天关于websocket的配置
1、nginx配置文件
server下面配置如下:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_read_timeout 86400s;
再添加接口、管理后台、socket的相关配置
location /myChat/ {
proxy_redirect off;
proxy_pass http://127.0.0.1:8009;
proxy_connect_timeout 3000s; #配置点1
proxy_read_timeout 86400s; #配置点2,如果没效,可以考虑这个时间配置长一点
proxy_send_timeout 3600s; #配置点3
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header REMOTE-HOST $remote_addr;
#proxy_bind $remote_addr transparent;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
proxy_set_header Connection "Upgrade";
# rewrite /myChat/(.*) /$1 break;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
client_max_body_size 50m;
}
location /app/{
proxy_pass http://127.0.0.1:8009/app/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
#缓存相关配置
#proxy_cache cache_one;
#proxy_cache_key $host$request_uri$is_args$args;
#proxy_cache_valid 200 304 301 302 1h;
#持久化连接相关配置
proxy_connect_timeout 3000s;
proxy_read_timeout 86400s;
proxy_send_timeout 3000s;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
add_header X-Cache $upstream_cache_status;
#expires 12h;
}
location /api/admin/ {
proxy_pass http://127.0.0.1:8009/admin/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
#缓存相关配置
#proxy_cache cache_one;
#proxy_cache_key $host$request_uri$is_args$args;
#proxy_cache_valid 200 304 301 302 1h;
#持久化连接相关配置
proxy_connect_timeout 3000s;
proxy_read_timeout 86400s;
proxy_send_timeout 3000s;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
add_header X-Cache $upstream_cache_status;
#expires 12h;
}
2、安装相关软件rabbitmq
安装相关依赖-Erlang
1-1、安装存储库
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
1-2、下载erlang包
wget --content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/8/erlang-25.2-1.el8.x86_64.rpm/download.rpm?distro_version_id=205
1-3、安装erlang包
yum install erlang-25.2-1.el8.x86_64.rpm
安装RabbitMQ及配置
1-1、安装存储库
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
1-2、下载erlang包
wget --content-disposition "https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/9/rabbitmq-server-3.13.4-1.el8.noarch.rpm/download.rpm?distro_version_id=240"
1-3、安装erlang包
yum install rabbitmq-server-3.13.4-1.el8.noarch
配置RabbitMQ
设置开机自启动
systemctl enable rabbitmq-server
启动
service rabbitmq-server start
查看状态
service rabbitmq-server status
停止
service rabbitmq-server stop
启用Management Plugin
rabbitmq-plugins enable rabbitmq_management
设置用户及授权
新建一个用户并设置密码
rabbitmqctl add_user 用户名 '密码'
给这个用户分配管理员权限
rabbitmqctl set_user_tags 用户名 administrator
设置配置文件
(一般在/etc/rabbitmq/conf.d/下面,没有的话自行创建,否则连接不上)
1、查看rabbitmq详细信息及配置文件位置
rabbitmqctl status
2、"/etc/rabbitmq/conf.d/10-defaults.conf"文件内容如下:
## DEFAULT SETTINGS ARE NOT MEANT TO BE TAKEN STRAIGHT INTO PRODUCTION
## see https://www.rabbitmq.com/configure.html for further information
## on configuring RabbitMQ
## allow access to the guest user from anywhere on the network
## https://www.rabbitmq.com/access-control.html#loopback-users
## https://www.rabbitmq.com/production-checklist.html#users
loopback_users.guest = false
## Send all logs to stdout/TTY. Necessary to see logs when running via
## a container
log.console = true
3、"/etc/rabbitmq/conf.d/20-management_agent.disable_metrics_collector.conf"文件内容如下:
# Enable Prometheus-style metrics by default (https://github.com/docker-library/rabbitmq/issues/419)
management_agent.disable_metrics_collector = true