所以我使用certbot为https配置Nginx。效果很好(我使用了自动配置(。
现在,我如何配置我的 Node.js 后端,以便能够从使用 Nginx 托管的前端发出 GET/POST 请求?
编辑:
location /api {
proxy_pass http://localhost:3000; #server port
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
如果您已使用 SSl 和节点应用程序正确配置了 Nginx。您发送的请求应适用于 https://URL .请检查您的nginx.conf并验证以下内容。
您可以在 Nginx 中添加 SSL 证书
ssl_certificate /etc/nginx/ssl/server.crt #cert location
ssl_certificate_key /etc/nginx/ssl/server.key #key location
在 Nginx 的服务器块中,并且您的 nodejs 应用程序应该在服务器块中像这样配置
location / {
proxy_pass http://localhost:3000; #server port
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
这足以使您的服务器使用 SSL。