首页 > 解决方案 > NGINX 在相同的 url 上提供内容而无需重定向

问题描述

我有一个应用程序用于从我的网站上获取此 URL 上的数据 -

example.com/android/android_script.php?table=something&content=otherthing

我的网站是在 apache2 上使用 vanilla PHP 和 jquery 构建的。我在 NGINX 上使用 nuxt 和 laravel 重新制作了我的网站。我为后端连接设置了 /api 路由。我无法在我的 Android 应用中更改我的 URL,因此我试图在同一个 URL 上提供内容。我正在像这样在 Nginx 中重定向该 URL -

rewrite ^/android/android_script3.php$ /api/android permanent;
//it changes 
//example.com/android/android_script.php?table=something&content=otherthing
//to 
//example.com/api/android?table=something&content=otherthing

它可以在浏览器中运行,但是当我打开应用程序时,数据加载在应用程序中不起作用。现在我想在同一个 URL 上提供相同的内容而不进行重定向。

标签: nginx

解决方案


我使用了代理通行证。

location = /android/android_script.php {
             proxy_pass https://example.com/api/android;
             proxy_redirect off;
             proxy_http_version 1.1;
             proxy_set_header Connection "";
             proxy_set_header  X-Real-IP  $remote_addr;
             proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
             }

推荐阅读