【发布时间】:2021-07-28 14:33:50
【问题描述】:
我有一个托管在 Firebase 主机上的前端应用。我还有一个在 Digital Ocean 液滴上运行的后端 API。我在 droplet 上安装了 nginx,它将重定向到前端应用程序或后端 API。我的 nginx 配置文件如下所示:
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name myapp.com *.myapp.com;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
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://150.101.64.193:80;
proxy_read_timeout 90;
proxy_redirect http://150.101.64.193:80 https://myapp.com;
}
location /api/ {
proxy_pass http://localhost:5000;
proxy_read_timeout 90;
proxy_redirect http://localhost:5000 https://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Firebase 告诉我将两条 TXT 记录复制到我的 DNS 设置中,但只有在我想将域名映射到前端应用程序时才能让它工作。相反,我的 DNS 设置将我的域名映射到 droplet 的 IP 地址。然后,Droplet 上的代理应根据传递的路由将请求转发到前端或后端。例如
www.myapp.com/blah 重定向到 Firebase 应用 www.myapp.com/api/blah 重定向到 API
目前 Firebase 报告说我的自定义域需要设置,因为没有相应的 TXT 记录。这是我第一次尝试部署 Web 应用程序,所以我不确定此设置是否有效。
【问题讨论】: