前景:已经使用supervisor把FastAPI开发的后端服务挂载到端口上
Nginx的配置如下:
upstream huiyuan_api { server 127.0.0.1:9120; } server { server_name hui.waketzheng.top; client_max_body_size 30m; location /api { 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; proxy_pass http://huiyuan_api; } location / { 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; proxy_pass http://huiyuan_api; } location /media { alias /home/wenping/coding/huiyuan/media; } location /static { alias /home/wenping/coding/huiyuan/static; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/hui.waketzheng.top/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/hui.waketzheng.top/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = hui.waketzheng.top) { return 301 https://$host$request_uri; } # managed by Certbot server_name hui.waketzheng.top; listen 80; return 404; # managed by Certbot }
配置完之后,别忘记sudo nginx -t && sudo nginx -s reload
标签:set,managed,ssl,Nginx,FastAPI,配置,header,proxy,Certbot From: https://www.cnblogs.com/waketzheng/p/16919164.html