fastapi: 用nginx做fastapi的反代
一,配置nginx,做反向代理
创建配置文件,内容如下:
upstream ycai_servce {
server 127.0.0.1:8008;
}
server {
listen 80;
listen 443 ssl;
server_name aiservice.domainname.com;
root /opt/project/aiservice;
if ($scheme = http ) {
#return 301 https://$host$request_uri;
}
if ($http_x_forwarded_proto = "http") {
#rewrite ^(.*)$ https://$host$1 permanent;
}
ssl_certificate /opt/ssl/api.domainname.com.pem;
ssl_certificate_key /opt/ssl/api.domainname.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
#ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
proxy_intercept_errors on;
recursive_error_pages on;
charset utf-8;
client_max_body_size 60m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
access_log /var/log/nginx/aiservice.domainname_access.log;
error_log /var/log/nginx/aiservice.domainname_error.log;
location / {
proxy_read_timeout 1800;
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_pass http://ycai_servce;
}
}
二,重启nginx服务:
sudo nginx -s stop
或:
systemctl reload nginx.service
浙公网安备 33010602011771号