为 AWS 中托管的网站设置 HTTPS,但指向局域网中的 webAPI



我正在做一个项目,我们在 AWS 上托管一个网页。该网页从局域网计算机名称 IE:Server-24.Local 调用 webAPI。 此方法可确保数据不会离开网络,因为Server-24.Local不会暴露在Internet上。 到目前为止,这种方法效果很好。但是,当我通过 certbot 启用 HTTPS 时,我遇到了问题:

如果我尝试将nginx proxy_pass到本地主机上AWS中托管的webapi,HTTPS工作正常。 但是,如果我将nginx proxy_pass Server-24.Local,它将返回跨源错误。 这两个 Web API 都启用了 CORS。

有人可以有任何建议吗?

你可以研究一下在互联网上启用的Nginx CORS...这是关于 chrome 等中的最终用户浏览器安全性......

这是一个例子,把它放在位置标签{}内

#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}

你可以帮忙看看这里 [https://enable-cors.org/server_nginx.html] ...

希望这对您有所帮助...

最新更新