Issue
I have one ajax request in site, it has a code like below:
$.ajax({
type: "POST",
url: '<?php echo Yii::app()->createAbsoluteUrl("site/checkstatus"); ?>',
data:"user_id="+user_id+"",
dataType:'html'
}).success(function(){ dontBlock = false; }).complete(function(){
alert('Success');
});
Now it is working fine in live site. It has a domain like https://example.com. Now i have to move this site into load balancing server. So i have created domain like https://ww.example.com and linked up that domain with load balancer server. But now the ajax request is sent using http instead of https.
I have checked the documentation and it says that schema to use (e.g. http, https). If empty, the schema used for the current request will be used. So suppose i am visited the site using URL like this: https://ww.example.com/index.php?r=controller/action then shouldn't it take the https request?
Solution
Your load balancer may be incorrectly configured to pass on HTTPS requests. Your load balancer may receive HTTPS requests but passes them on to your application servers via HTTP. As such the request from the application server's point of view is a HTTP request.
The function determining the schema is CHttpRequest::getIsSecureConnection
as below:
public function getIsSecureConnection() {
return isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'],'on')===0 || $_SERVER['HTTPS']==1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'],'https')===0;
}
To fix it ensure that your load balancer inserts a HTTP_X_FORWARDED_PROTO
header when passing on the request to the application servers.
Answered By - topher
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.