nginx 解决tensorflow-serving 跨域代理问题

发布时间:2024年01月24日

在nginx conf.d/目录下新建一个main.conf? 配置该文件? 进行代理?

   upstream rec{
     server 127.0.0.1:19356  ;
     keepalive 20000;
    }
    upstream rcv-module{
     server 10.0.2.198:8511  ;
     keepalive 20000;
    }
server {
    listen       80;
    server_name  **.**.com;

    #access_log  /var/log/nginx/host.access.log  main;

    	location /rec {
            proxy_pass http://rec;
                        proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_connect_timeout 75;
            proxy_read_timeout 300;
            proxy_send_timeout 300;
            proxy_buffer_size 64k;
            proxy_buffers   4 64k;
            proxy_busy_buffers_size 128k;
            proxy_temp_file_write_size 128k;
            add_header  Cache-Control  max-age=no-cache;
            expires 0;

        }

       location /mi {
            proxy_pass http://rcv-module/v1;
 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_set_header X-Forwarded-Proto $scheme;

        # 添加以下跨域头
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        add_header 'Access-Control-Allow-Credentials' 'true';

        }

}

文章来源:https://blog.csdn.net/zb313982521/article/details/135828474
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。