本文介绍了Nginx URL 屏蔽到不同的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SO 上有一些类似的问题,但没有一个是我的,到目前为止我还没有尝试调整他们的答案.

There's a few similar questions on SO, but none exactly mine, and I've had no luck trying to adapt their answers so far.

我想将 URL http://sub.example.com 映射到 https://123.12.12.12/path,这样浏览器仍然显示URL http://sub.example.com.

I want to map the URL http://sub.example.com to https://123.12.12.12/path, such that the browser still shows the URL http://sub.example.com.

我的 Nginx 配置文件看起来像,

My Nginx config file looks like,

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

    location / {
        proxy_pass https://123.12.12.12;
        rewrite ^/$ /path last;
    }
}

路由在这里工作,但显示的 URL 是 http://sub.example.com/path.如何让它只显示 http://sub.example.com?

The routing works here, but the URL displayed is http://sub.example.com/path. How do I make it display only http://sub.example.com?

推荐答案

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

    location / {
        proxy_pass https://123.12.12.12/path;
    }
}

这就是它的工作原理.如果 proxy_pass 包含位置部分 - 当前位置将被替换为指定的.http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

Thats how it works. If proxy_pass contains locations part - current location will be replaced to specified. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

但它仅对 http 请求和 http 重定向有帮助.如果应用程序创建带有链接 https://123.12.12.12 的 html - 它仍然保持不变.在这种情况下,您可以尝试使用 ngx_http_sub_module.

But it's help only for http request and http redirects. If application create html with links https://123.12.12.12 - it's still unchanged. In this case you can try ngx_http_sub_module.

这篇关于Nginx URL 屏蔽到不同的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:18