我创建了一个应用程序,并将其部署在DigitalOcean上,并且具有SSL证书。有2台分离的服务器,其中1台用于角度服务器,其中1台具有用于https重定向的平衡器加载程序,而1台用于后端服务器,但是当我打开网站时,会在控制台中找到它。
Mixed Content: The page at 'https://www.mirrorate.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://165.22.187.137/api/posts?pagesize=2&page=1'. This request has been blocked; the content must be served over HTTPS.
有人可以向我解释一下吗?或我如何解决这个问题,谢谢!
答案 0 :(得分:0)
出于安全考虑,您不能通过http进行https呼叫。
要解决您的问题,您可以设置nginx通过https代理您的HTTP后端URL。 使用nginx服务器,您将需要像https://your_domain/api/some_path那样调用api,nginx会将您的请求代理到api主机,该主机将在config中设置
示例配置。 PS-不要忘记更改证书文件路径:
# if you have sockets
upstream socket {
ip_hash;
server host:port fail_timeout=0;
}
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl default_server;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
client_max_body_size 50M;
# server_name YOUR_SERVER_NAME
ssl_certificate /fullchain.pem;
ssl_certificate_key /privkey.pem;
include /options-ssl-nginx.conf;
ssl_dhparam /ssl-dhparams.pem;
location /ws/ {
proxy_pass http://socket;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /api {
proxy_pass http://host:port/api;
}
location / {
try_files $uri $uri/ /index.html;
}
}
答案 1 :(得分:0)
如果您的角度应用程序通过HTTP(S),则无法向HTTP服务器发出请求,因为中断了协议HTTPS,并且浏览器不允许这样做。您需要HTTP(S)后端或HTTP前端。