大网数据广告活动
服务器运维问答

Use NGINX to map "directories" to applications

· 52CE 我爱测

I'm not sure if my terminology is correct, so let me explain ... If I have a domain, test.example.com , I want to be able to map /abc to an application on that server running on port 8080 and map another application /def to an ap…

问题原文

原帖链接 · Jan Vladimir Mostert · CC BY-SA 3.0

I'm not sure if my terminology is correct, so let me explain ...

If I have a domain, test.example.com, I want to be able to map /abc to an application on that server running on port 8080 and map another application /def to an application running on port 8081.

I've tried it with RabbitMQ which I'm running inside docker and exposing port 15672, NGINX however is not inside Docker and running directly on the machine.

docker run -d --hostname rabbitmq --name rabbitmq -p 15672:15672 rabbitmq:3-management

Whether it's running inside Docker or directly on the machine, I believe is irrelevant, I have an application running on port 15672 that I want to map to location /rabbitmq

My NGINX config I've tried so far:

server {
        listen 80;
        server_name test.example.com;

        location /rabbitmq {
                proxy_pass      http://127.0.0.1:15672;
        }
}

When going to test.example.com/rabbitmq I'm seeing the following:

I don't know if that's NGINX's page or RabbitMQ's page showing not found.

Opening port 15672 on the server I can clearly get to RabbitMQ

And going to :15672/blah it seems to be the same not-found page, so it must be getting to RabbitMQ.

RabbitMQ is listening on 0.0.0.0:15672, so it should work from any domain, host or ip.

So how do I make test.example.com/rabbitmq actually serve the content of test.example.com:15672 ?

已采纳解答

原帖链接 · Jan Vladimir Mostert · CC BY-SA 3.0

I got it working using a rewrite:

server {
        listen 80;
        server_name test.example.com;

        location /rabbitmq {
                rewrite         /rabbitmq/(.*) /$1 break;
                proxy_pass      http://127.0.0.1:15672;
                proxy_redirect  off;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。