i am hosting a website on aws lighsail server. it is single server and i am running 4 docker container on it. 1-nginx , 2-node js, 3- spring bot, 4 - mysql.
As for now my website is loading great with this :
server {
listen 80;
server_name *.example.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
client_max_body_size 100M;
location / {
proxy_pass http://cahub-client:4000;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://microservice:8080;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
I have purchased ssl certificate from goddady, and now installing on my server.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.domain.com;
ssl_certificate /etc/nginx/certs/cae51a61335308544.pem;
ssl_certificate_key /etc/nginx/certs/www.eaxmple.com.key;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
client_max_body_size 200M;
location / {
proxy_pass http://cahub-client:4000;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://microservice:8080;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
So what is happening here is now. that when i type my domain in url it goes and redirect to https but only angular client location block is getting run which is my frontend. but whenever a call from frontend to backend is made. it should also go to my reverse proxy block /api.. this is not reolvong instead getting an error mixedcontext found. when i see in network tab. My frontend call is going as https://example.com but my backend call is going as earlier http://example.com/api/.
You need to fix your frontend app so that it makes backend calls to
https://example.com/api
instead ofhttp://example.com/api
.