nginx入口后面的nginx代理传递给vhost端口不起作用

时间:2018-09-26 12:53:58

标签: amazon-web-services nginx kubernetes nginx-ingress kubernetes-helm

我们有计划

 ELB => (Nginx proxy => Nodejs)containers

现在我们要使用kubernetes和nginx入口

 ELB => Nginx Ingress (Load Balancer) => (Nginx proxy => Nodejs)pod

nginx代理虚拟主机配置的一部分:

include /etc/nginx/redirect-map-domainb.conf;
include /etc/nginx/redirect-map-domaina.conf;
 server {
     listen 80;
     listen [::]:80;
     server_name domainb www.domainb;
     if ( $redirect_domainb ) {
         return 301 https://domaina$redirect_uri_domainb;
     }
     location / {
         return 301 https://domaina/en/company; } }

 server {
     listen 80;
     listen [::]:80;
     server_name domaina www.domaina;
     if ( $redirect_uri_domaina ) {
         return 301 https://domaina$redirect_uri_domaina;
     }
     location / {
         return 301 https://domaina/de/mobile; } }

 server {
     listen 1443;
     listen [::]:1443;
     server_name _;
     location /health_check {
         proxy_pass http://localhost:8000/ping;
         access_log off; }   }

 server {
     listen 443;
     listen [::]:443;
     server_name domaina www.domaina;
     if ( $redirect_uri_domaina) {
        return 301 https://domaina$redirect_uri_domaina;
     }
     root /app/dist;
       index index.html index.htm index.nginx-debian.html;
       access_log  /var/log/access.log logstash;
       error_log   /var/log/error.log;

     location / {
       proxy_pass http://localhost:8000;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
     }

服务Yaml:

 apiVersion: v1
    kind: Service
    metadata:
      name: web
      annotations: {}
      labels:
        app: web
    spec:
      ports:
      - name: http
        port: 80
        targetPort: 80
      - name: https
        port: 443
        targetPort: 443
      selector:
        app: web
      type: ClusterIP

部署Yaml的一部分:

ports:
    - name: nginxhttp
      containerPort: http
    - name: nginxhttps
      containerPort: https

part ingres控制器Yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: /

    name: dev-ingress
    namespace: default
spec:
  rules:
  - host: domaina
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 443
  - host: domainb
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 80

我们使用值文件的掌舵部分安装了nginx入口

service:
    annotations:
       service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
       service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "3600"
       service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
       service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:eu-west-1:565638931841:certificate/2222...
       service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https


  targetPorts:
      http: http
      https: https

  type: LoadBalancer

我们遇到错误 普通的HTTP请求已发送到HTTPS端口 如何从入口路由到Nginx代理虚拟主机端口? 使工作从http://domaina重定向到https://domaina

0 个答案:

没有答案