我正在尝试创建一个条件代理,它将代理以“DirectToHTTP”结尾的 URL(来自 localhost:7012)请求到另一个 http 服务器(位于 localhost:8012)。配置文件的其余部分运行良好(重定向到 https 中的 localhost:877X),但代理不起作用。我哪里做错了?(我是 nginx 和 Web 服务器的新手)非常感谢!:)
Nginx配置文件主要内容:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 7012 ;
server_name someservername;
set $new_uri "${request_uri}";
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
if ($new_uri ~ (.*)DirectToHTTP) {
proxy_pass http://localhost:8012;
break;
}
}
if ($request_method = GET) {
return 301 https://localhost:8773$new_uri;
}
if ($request_method = POST) {
return 307 https://localhost:8773$new_uri;
}
if ($request_method = PUSH) {
return 307 https://localhost:8773$new_uri;
}
return 301 https://localhost:8773$new_uri;
}
}