Nginx重定向配置问题

时间:2018-04-03 08:33:21

标签: nginx openshift bitnami

我在Openshift中部署了nginx bitnami容器,为我的应用程序提供服务。我面临的问题是重定向无效。在日志中,没有迹象表明请求被proxy_pass位置块捕获。

因此。我们的想法是将app.com/backend1/api/something的请求转发给service1.com/backend1/api/something。 service2也是如此。

worker_processes 1;

events {
  worker_connections 1024;
}

http {

    upstream service1 {
      server service1.com;
    }

    upstream service2 {
      server service2.com;
    }

    server {
      listen 8443 ssl;
      listen [::]:8443 http2 ssl;

      server_name app.com;

      error_log  /opt/bitnami/nginx/error.log  debug;


      ssl on;
      ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
      ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
      ssl_dhparam /etc/ssl/certs/dhparam.pem;

      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_prefer_server_ciphers on;
      add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
      ssl_session_cache   shared:SSL:10m;
      ssl_session_timeout 10m;
      keepalive_timeout   70;

      include /opt/bitnami/nginx/conf/mime.types;

      root /opt/bitnami/nginx/html;

      location ~ ^/backend1/api/(.*)$ {
        proxy_pass https://service1/backend1/api/$1;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
      }

      location ~ ^/backend2/api/(.*)$ {
        proxy_pass https://service2/backend2/api/$1;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
      }

      location / {
        try_files $uri /index.html;
      }

    }
}

我也试过移动location块的顺序,以及移动root指令,但没有成功。

有关如何解决此问题的任何想法?

0 个答案:

没有答案