grpc使用nginx代理配置

參考:https://www.nginx.com/blog/nginx-1-13-10-grpc/

重點是標記紅色的部分

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent"';
 
    server {
        listen 80 http2;
 
        access_log logs/access.log main;
 
        location / {
            # Replace localhost:50051 with the address and port of your gRPC server
            # The 'grpc://' prefix is optional; unencrypted gRPC is the default
            grpc_pass grpc://localhost:50051;
        }
    }
}

 

比如下面這個:

這裏配置用的是openresty,-V查看的時候並沒有查看到grpc相關模塊,就能支持了,可能是已經有人裝了模塊了吧,或者默認就能用?

訪問:http://xxx.internalxxx.com:50051

生產配置案例:


upstream xxx-internalxx50051 {
server 10.0.0.49:50051  weight=10000 max_fails=3;
 server 10.0.0.193:50051  weight=10000 max_fails=3;
 server 10.0.0.41:50051  weight=10000 max_fails=3;
    keepalive 64;
}


server {
    listen 50051 http2;
    server_name xxx.internalxxx.com;

    location / {
            grpc_pass grpc://xxx-internalxx50051;
          
            #proxy_pass http://xxx-internalxx50051;
            #proxy_redirect    off;
            #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_http_version 1.1;
    }


    access_log /data/logs/nginx/xxx-internalxx2_access.log main;
    error_log /data/logs/nginx/xxx-internalxx2_error.log;
}

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章