带变量的nginx后端项目配置
不同的api项目,挂载不同的域名,只需在配置夹里,修改文件名(建议文件名和域名保持一致)、修改端口号、修改第5行第22行backend_api后面的编号、修改第11行的项目名、可能还需要修改第12行的文件夹名、修改第14行的域名
$ cat /etc/nginx/sites-avaliable/myapi.waketzheng.top
upstream backend_api_1 {
server 127.0.0.1:9376;
}
server {
set $project "myapi";
set $codedir "/home/ubuntu/coding";
server_name myapi.waketzheng.top;
client_max_body_size 10m;
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://backend_api_1;
}
location /media {
alias $codedir/$project/media;
}
location /static {
alias $codedir/$project/static;
}
listen 80;
}
标签:set,fastapi,variables,project,header,api,proxy,backend
From: https://www.cnblogs.com/waketzheng/p/17466661.html