首页 > 解决方案 > 在端口 8080 上向本地服务器发出请求

问题描述

我现在有以下流程。

example.com => https://example-example.mycompany.com => myproxy => someServer

我现在正在开发myproxy,它改变了网站客户example.com收到的答案。

为了测试这一点,我认为我能想到的最好的主意是更改我的本地机器(其中我有一个myproxy在端口上运行的实例8080)所以我只重定向我的请求example-example.mycompany.comlocalhost:8080

我已经尝试nginx添加以下配置,但我无法......而且改变/etc/hosts也没有帮助我。

问题

有什么方法可以更改我的计算机的example-example.mycompany.com JUST调用,以便在我测试时没有客户端example.com受本地更改的影响myproxy

试验

docker run --name my-custom-nginx-container -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro -p 80:80 -p 3000:8080 --rm -d nginx

nginx.conf

server {
            listen   80;
            server_name example-example.mycompany.com;

            location / {
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $host;
                    proxy_set_header X-NginX-Proxy true;
                    proxy_pass http://localhost:3000/;
                    proxy_redirect http://localhost:3000/ https://$server_name/;
            }
    }

/etc/hosts

127.0.0.1 example-example.mycompany.com

注意:我已经看到它在使用 Windows 的同事的计算机上工作。我无法让它在 Linux/MacOs 中工作。

标签: node.jshttpnginxserverrequest

解决方案


推荐阅读