php和js:HTTP或HTTPS

I meet a trouble that determine HTTP or HTTPS on my server via php and javascript.

I use javascript like this:

window.onload = function(){
  alert(window.location.protocol);};

and it returns https

I use php like this:

echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')?'yes':'no';

and it echoes no

then, I try some other methods via php, but all of it cannot work well.

so I want to know why is that.

My Server is nginx and apache (nginx is agent)

From PHP documentation, $_SERVER['HTTPS'] is

set to a non-empty value if the script was queried through the HTTPS protocol.

Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.

http://php.net/manual/en/reserved.variables.server.php

So I think you may just check

echo (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')?'yes':'no';