关于SO有几个类似的问题,但没有一个完全是我的,到目前为止,我没有运气试图调整他们的答案.

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

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

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?
最佳答案

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

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

dawei

【声明】:丽水站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。