nginx - RabbitMQ nginx 配置

标签 nginx rabbitmq centos7

我在服务器中输入 RabbitMQ 管理页面时遇到问题,它要求每个请求基本身份验证登录。我无法解决它,因此我没有输入每个请求。 这是我的 nginx 配置:

location ~* /rabbitmq/api/(.*?)/(.*) {
    #rewrite         ^/rabbitmq/api/(.*) /$1 break;
    proxy_pass http://127.0.0.1:15672/api/$1/%2F/$2?$query_string;
    allow all;
}

location ~* /rabbitmq/(.*) {
    rewrite         ^/rabbitmq/(.*) /$1 break;
    proxy_pass     http://127.0.0.1:15672;
    allow all;
}

版本:

nginx version: nginx/1.11.2

有人可以帮忙吗?

最佳答案

在寻求帮助时,如果您提供完整配置文件而不是像您所做的那样只是一个片段,这会对人们有所帮助。

这是一个完整的配置,它将localhost:8888/rabbitmq重定向到在端口15672上运行的管理服务器。我已经使用 nginx 1.14.0 和 RabbitMQ 3.7.6 对其进行了测试。我只被提示登录一次。我以普通用户身份使用以下命令运行它:

nginx -p /home/lbakken/issues/SO/rabbitmq-nginx-config-48881248 -c nginx.conf
user                 lbakken lbakken;
worker_processes     1;
# Note: for debugging, very useful
# error_log            /dev/stderr debug;
error_log            /dev/stderr;
pid                  nginx.pid;
worker_rlimit_nofile 1024;
daemon               off;

events {
    worker_connections 1024;
}

http {
    client_body_temp_path /tmp/nginx;
    fastcgi_temp_path     /tmp/nginx;
    scgi_temp_path        /tmp/nginx;
    uwsgi_temp_path       /tmp/nginx;
    proxy_temp_path       /tmp/nginx;
    access_log            /dev/stdout;

    upstream rabbitmq {
        least_conn;
        server localhost:15672 weight=10 max_fails=3 fail_timeout=30s;
    }

    server {
        listen                          8888;
        server_name                     127.0.0.1;

        # Note: a big thanks to this answer:
        # https://stackoverflow.com/a/37584637
        location /rabbitmq/api/ {
            rewrite ^ $request_uri;
            rewrite ^/rabbitmq/api/(.*) /api/$1 break;
            return 400;
            proxy_pass http://rabbitmq$uri;
        }

        location /rabbitmq {
            rewrite ^/rabbitmq$ /rabbitmq/ permanent;
            rewrite ^/rabbitmq/(.*)$ /$1 break;
            proxy_pass http://rabbitmq;
            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;
        }
    }
}

关于nginx - RabbitMQ nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48881248/

相关文章:

node.js - 如何在单个 digitalocean vps 服务器中为多个 Node 应用程序提供服务?

nginx - 将 header 位置从 HTTP 重写为 HTTPS

activemq - 从 ActiveMQ 切换到 RabbitMQ

firewall - 在 Centos7 中向 firewalld 添加规则以允许来自服务器的所有流量

linux-kernel - 通过清除高位来保持内核地址平衡?

nginx - nginx:配置文件/etc/nginx/nginx.conf测试失败(在上游找不到主机)

RabbitMQ 直接交换 : default vs.

java - 在同一 channel 上消费和发布消息

java - Tomcat 7 + JNI : UnsatisfiedLinkError: cannot open shared object file: No such file or directory

nginx - 单页应用程序的服务器端路由