展开

k8s 容器应用代理-nginx

最后发布时间 : 2024-11-16 15:04:12 浏览量 :

代理Rstudio

spring:
  cloud:
    gateway:
      routes:
        - id:  docker-app
          uri: http://192.168.3.60:82
          predicates:
            - Path=/cloud-gateway/app/**
        - id:  docker-cloud-gateway-rapp
          uri: http://192.168.3.60:82
          predicates:
            - Path=/cloud-gateway/rapp/**
location /cloud-gateway/rapp/ {
        #proxy_read_timeout 5s; 
        proxy_set_header Connection "keep-alive";
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:40000/cloud-gateway/rapp/;
        # proxy_pass  http://localhost:82/cloud-gateway/rapp/;
}


location /cloud-gateway/app/  {
        proxy_set_header Connection "keep-alive";
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://localhost:40000/cloud-gateway/app/;
}
server {
    listen 82;
    charset utf-8;
     client_max_body_size 200m;

    large_client_header_buffers 4 16k;
    #root /ssd1/shanjun/applications/web/;
    location /cloud-gateway/app/ { 
        add_header request_uri "$request_uri";
        if ($request_uri ~ /app/(.+)){
            set $rightUrl $1; 
        }

        if ($request_uri ~ /app/(.+)/){
            set $secondUrl $1;
        }
        add_header X-debug-message "A static file was served" always;
        proxy_pass http://192.168.3.60:$rightUrl;
#       proxy_redirect  default;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header bbb "$rightUrl";
        add_header ccc "$secondUrl";
        proxy_set_header Origin "";
        rewrite ^/app/$rightUrl(.*)$ /$1 break;
        proxy_redirect http://192.168.3.60 http://192.168.3.60:30000/app/8788/;
#       proxy_redirect http://10.110.1.11 /app/$secondUrl;

            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            #proxy_pass http://10.110.1.12:8080;
    }   
    location /rnode/ { 
        add_header request_uri "$request_uri";
        if ($request_uri ~ /rnode/(.+)){
            set $rightUrl $1; 
        }

        if ($request_uri ~ /rnode/(\d+)/){
            set $secondUrl $1;
        }
        add_header X-debug-message "A static file was served" always;
        proxy_pass http://192.168.3.60:$secondUrl/;
#       proxy_redirect  default;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        #proxy_set_header Host $host;
        #proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header bbb "$rightUrl";
        add_header ccc "$secondUrl";
        proxy_set_header Origin "";
        rewrite ^/rnode/$secondUrl$ /$1 break;
        proxy_redirect http://192.168.3.60 http://192.168.3.60:30000/app/8788/;
#       proxy_redirect http://10.110.1.11 /app/$secondUrl;

            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            #proxy_pass http://10.110.1.12:8080;
    }   

    location /rapp/ { 
        add_header request_uri "$request_uri";
        if ($request_uri ~ /rapp/(.+)){
            set $rightUrl $1; 
        }

        if ($request_uri ~ /rapp/(\d+)/ ){
            set $secondUrl $1;
        }
        add_header X-debug-message "A static file was served" always;
        proxy_pass http://192.168.3.60:$secondUrl;
#       proxy_redirect  default;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header bbb "$rightUrl";
        add_header ccc "$secondUrl";
        proxy_set_header Origin "";
       # rewrite ^/app/$rightUrl(.*)$ /$1 break;
        #proxy_redirect default;
        #proxy_redirect http://192.168.3.60 http://192.168.3.60:30000/app/8788/;
#       proxy_redirect http://10.110.1.11 /app/$secondUrl;

            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            #proxy_pass http://10.110.1.12:8080;
    }   
    location /cloud-gateway/rapp/ { 
        add_header request_uri "$request_uri";
        if ($request_uri ~ /rapp/(.+)){
            set $rightUrl $1; 
        }

        if ($request_uri ~ /cloud-gateway/rapp/(\d+)/ ){
            set $secondUrl $1;
        }
        add_header X-debug-message "A static file was served" always;
        proxy_pass http://192.168.3.60:$secondUrl;
#       proxy_redirect  default;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header bbb "$rightUrl";
        add_header ccc "$secondUrl";
        proxy_set_header Origin "";
       # rewrite ^/app/$rightUrl(.*)$ /$1 break;
        #proxy_redirect default;
        #proxy_redirect http://192.168.3.60 http://192.168.3.60:30000/app/8788/;
#       proxy_redirect http://10.110.1.11 /app/$secondUrl;

            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            #proxy_pass http://10.110.1.12:8080;
    }   



    location /node/ {
        proxy_pass http://192.168.3.60:8788;
        rewrite ^/node/(.*)$ /$1 break;
                    proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        proxy_set_header Origin "";
        proxy_redirect  http://192.168.3.60:8788 /node;
    }
}

开发

  server: {
    port: 8889,
    proxy: {
      '/service-': {
        target: `http://192.168.10.177:30000`,
      },'/cloud-gateway': {
        target: `http://192.168.10.177:40000`,
      },
    },
  },
        - id:  docker-app
          uri: http://192.168.10.176:80
          predicates:
            - Path=/cloud-gateway/app/**
            location /cloud-gateway/app/ { 
                add_header request_uri "$request_uri";
                if ($request_uri ~ /app/(.+)){
                    set $rightUrl $1; 
                }
            
                if ($request_uri ~ /app/(.+)/){
                    set $secondUrl $1;
                }
                add_header X-debug-message "A static file was served" always;
                proxy_pass http://192.168.10.177:$rightUrl;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header bbb "$rightUrl";
                add_header ccc "$secondUrl";
                proxy_set_header Origin "";
                rewrite ^/app/$rightUrl(.*)$ /$1 break;
            }