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

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

这是我的 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 localhost;
    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 似乎被选中,并且这里指定的内容被选中 location / { }

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

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

它应该重定向到 location /login/ { proxy_passhttps://springbootapi.ecs.dyn.net但它在角度内重定向如下,并出现错误

HttpErrorResponse {headers:HttpHeaders,status:503,statusText:'服务不可用',url:'https://angularapp.ecs.dyn.net/login/getSecurityKeyVal',ok:false,…}

尝试了所有可能的选择

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。

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

authenticate(): Observable<ConfigModel> {    
        return this.http.get<ConfigModel>("https://springbootapi.ecs.dyn.net"+"/login/authenticate", this.httpOption);
      }

相关内容