worker_processes  1;
events {
    worker_connections  1024;
}
http{
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  165;
    log_format  main  'host=$host|$http_x_forwarded_for|$http_x_real_ip|remote_addr=$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';              
    upstream uuuuu{
        #远程服务器端口是80,就省略端口
        server xxxx.xxx.com(你的域名或IP):端口 max_fails=10 fail_timeout=300s weight=1;
        #server 127.0.0.1:8901 weight=1;
    }
    server {
        # nginx 对外暴漏的端口
        listen       80;
        server_name  xxxx.xxx.com(你的域名或IP);#服务接口在哪里,这个就写那个接口所在的服务器域名或IP
        access_log  logs/host.access.log  main;
        location / {
            proxy_pass http://uuuuu/;
            default_type application/json;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
            add_header 'Access-Control-Max-Age' 1728000;
            if ($request_method = 'OPTIONS') {
               return 204;
            }
            client_max_body_size  500m;
            proxy_http_version 1.1;
            proxy_connect_timeout 980;
            proxy_read_timeout 800;
            proxy_send_timeout 800;
            proxy_redirect      off;
            proxy_set_header    Host             $server_name;# 远程是域名的时候最好使用server_name
            proxy_set_header    X-Real-IP        $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            add_header Content-Type 'application/json; charset=utf-8';
        }
    }
}


 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐