简体   繁体   English

代理页面中的nginx重写URL

[英]nginx rewrite url in the proxy page

I have some trouble with a page that is running trough a nginx proxy. 我在通过nginx代理运行的页面上遇到了一些麻烦。 This page does calls other internal servers and I would like to rewrite these URLs with nginx. 该页面确实调用了其他内部服务器,我想用nginx重写这些URL。

I already have a proxy pass running for the following: 我已经有以下代理运行:

foo.site.internal --> foo.site.nl (public) The site internal, calls for some other services like: foo2.site.internal:1400/json/api/call/bla foo.site.internal-> foo.site.nl(公共)网站内部需要其他一些服务,例如:foo2.site.internal:1400 / json / api / call / bla

Currently foo.site.nl is trying to receive those calls by some javescript usage. 当前foo.site.nl正在尝试通过一些javescript用法来接收这些调用。 But this is not possible because the end user can't connect to foo2.site.internal 但这是不可能的,因为最终用户无法连接到foo2.site.internal

So I have created a reverse proxy for: foo2.site.internal:1400 that is running at: foo.site.nl:1400, so what I would like to accomplish without changing the config of the backend site is this: 因此,我为在以下位置运行的foo2.site.internal:1400创建了一个反向代理:foo.site.nl:1400,因此我想在不更改后端站点配置的情况下完成以下任务:

rewrite foo2.site.internal:1400/json/api/call/bla in page to foo.site.nl:1400/json/api/call/bla 将页面中的foo2.site.internal:1400 / json / api / call / bla重写为foo.site.nl:1400/json/api/call/bla

Could such a thing be possible with nginx? Nginx可以实现这种功能吗?

My current config: 我当前的配置:

server {
   listen 443 ssl;
   ssl_certificate /etc/nginx/ssl/site.nl.cert;
   ssl_certificate_key /etc/nginx/ssl/site.nl.key;

  server_name foo.site.nl;

  location / {
    proxy_intercept_errors on;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://foo.site.internal/;
  }
}

server {
  listen      14000 default_server;
  server_name foo.site.nl;
  location / {
    proxy_pass       http://foo2.site.internal:14000;
    proxy_set_header Host foo2.site.internal:14000;
  }
}

You can use this configuration : 您可以使用以下配置:

server {
   listen 443 ssl;
   ssl_certificate /etc/nginx/ssl/site.nl.cert;
   ssl_certificate_key /etc/nginx/ssl/site.nl.key;

  server_name foo.site.nl;

  location / {
    proxy_intercept_errors on;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://foo.site.internal/;
  }
}

server {
  listen      14000 default_server;
  server_name foo.site.nl;
  location / {
    try_files $uri $uri/ /index.php?$args;
    proxy_pass       http://foo2.site.internal:14000;
    proxy_set_header Host foo2.site.internal:14000;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM