163 字
1 分钟
Nginx反代Fastapi
Nginx配置文件
location ^~ /api{ proxy_pass http://127.0.0.1:7899; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; # proxy_hide_header Upgrade;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
set $static_filevM0NQDr8 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_filevM0NQDr8 1; expires 1m; } if ( $static_filevM0NQDr8 = 0 ) { add_header Cache-Control no-cache; }}此配置文件Fastapi可以获取到真实的IP地址和host以及Scheme,同时支持http2.0协议,支持缓存静态文件。
request.url.scheme+"://"+request.url.netloc Nginx反代Fastapi
https://blog.zzboy.tk/posts/nginx反代fastapi/