Openshift nginx proxy_pass 未从当前主机重定向到另一个主机

问题描述 投票:0回答:1

这是我的 DockerFile

FROM docker-enterprise.net/developers-nginx/nginx1.22/rhel8/nginx-rhel8:latest
USER root
RUN   mkdir /.ionicsecurity && \
      chmod 775 /.ionicsecurity && \
      mkdir /nginxapps && \
      mkdir /nginxapps/html && \
      mkdir /nginxapps/config
COPY nginx.conf /opt/middleware/nginx/latest/nginx/nginx.conf    
ADD . /nginxapps/html
USER 1001
EXPOSE 51000/tcp
CMD ["/tmp/scripts/nginx-entrypoint.sh"]

这是我的 nginx.conf

user cloudngx root;
worker_processes 1;

error_log  /opt/middleware/nginx/latest/log/nginx/error.log warn;
pid        /opt/middleware/nginx/latest/run/nginx.pid;
events { worker_connections 1024; }
 
http {
  charset utf-8;
  log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
  access_log /opt/middleware/nginx/latest/log/nginx/access.log cloudfoundry;
 
  default_type application/octet-stream;
  client_max_body_size 3G;
  include mime.types;
   
  server {
    #listen 4200;
    listen 51000 ssl;
    server_name *.ecs.dyn.net;
    underscores_in_headers on;

    ssl_certificate      /opt/middleware/nginx/latest/certs/server.crt;
    ssl_password_file   /opt/middleware/nginx/latest/certs/global.pass;
    ssl_certificate_key  /opt/middleware/nginx/latest/certs/server.key;
    
    location /login/ {          
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_pass https://springbootapi.ecs.dyn.net;
    }
        
    location /entitlement/ {                
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;       
        proxy_pass https://springbootapi.ecs.dyn.net;
    }
    
    location / {
        root /nginxapps/html/<%= ENV["APP_ROOT"] %>/public;
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';        
        index index.html;
        try_files $uri $uri/ /index.html;
    }
  }
}

我可以使用 https://angularapp.ecs.dyn.net 启动我的应用程序,所以对我来说,看起来 nginx.conf 已被选中,并且此处指定的内容被选中位置 / { }

当我从登陆页面触发任何操作时,请按如下方式登录

authenticate(): Observable<ConfigModel> {    
    return this.http.get<ConfigModel>("/login/authenticate", this.httpOption);
  }

它应该重定向到位置 /login/ { proxy_pass https://springbootapi.ecs.dyn.net } 中指定的 proxy_pass ,但它在角度内重定向,如下所示,出现错误

HttpErrorResponse {标头:HttpHeaders,状态:503,statusText: “服务不可用”,网址: 'https://angularapp.ecs.dyn.net/login/getSecurityKeyVal',好的: 假的,...}

尝试了所有可能的选项

location /login/ { 
proxy_pass https://springbootapi.ecs.dyn.net;
}

location /login/* { 
proxy_pass https://springbootapi.ecs.dyn.net;
}

location /login/ { 
proxy_pass https://springbootapi.ecs.dyn.net/login/;
}

但它甚至没有选择我在 proxy_pass 中提到的 url。

但是当我这样做时,它正在起作用。我有数百个类似的导航,并且不想进行硬编码。 Angular/Nginx 在 51000 中运行,Spring Boot 应用程序在 8443 中运行

authenticate(): Observable<ConfigModel> {    
        return this.http.get<ConfigModel>("https://springbootapi.ecs.dyn.net"+"/login/authenticate", this.httpOption);
      }
angular nginx openshift nginx-reverse-proxy
1个回答
0
投票

添加端口号后问题已解决

location /login/ { 
   proxy_pass https://springbootapi.ecs.dyn.net:443;
}
© www.soinside.com 2019 - 2024. All rights reserved.