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

Redirecting webhook with nginx

· 52CE 我爱测

I am changing the domain name of my app from old.com to new.com My app is connected to external APIs that send data through webhooks, and I would like to redirect the webhooks sent to the old url, so that they hit the new url and…

问题原文

原帖链接 · Buno · CC BY-SA 4.0

I am changing the domain name of my app from old.com to new.com

My app is connected to external APIs that send data through webhooks, and I would like to redirect the webhooks sent to the old url, so that they hit the new url and get processed.

I have a tried a plain rewrite

server {
  server_name old.com;
  listen 443 ssl;
  rewrite ^       https://new.com$request_uri;

I can see this triggers a 302 redirection, but that doesn't seem to do the trick..

I tried with a proxy_pass

server {
  server_name old.com;
  listen 443 ssl;

  location /webHook {
    proxy_pass https://new.com/webHook;
  }

  rewrite ^       https://new.com$request_uri;

Same result.. I can see a 302 redirect in the logs, but the webhook never seem to hit the new URL and doesn't get processed..

Any idea on how to achieve that?

已采纳解答

原帖链接 · Piotr P. Karwasz · CC BY-SA 4.0

The rewrite directives in the server block, which are not inside a location block are executed first (cf. ng_http_rewrite_module documentation).

So delete or comment the rewrite directive and the proxy_pass directive will get executed.

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

资料来源与适用范围

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

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

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