Scenario: I'm working on a Apache web server with some PHP. I point my browser at https://my.example.com/test.php that has the following lines of code in it:
<pre>
<?php
print_r($_SERVER);
?>
</pre>
The value printed out for SERVER_PORT is 80, not 443. But if I go to https://my.example.com:80/test.php the web server (Apache) barfs (An error occurred during a connection to my.example.com:80. SSL received a record that exceeded the maximum permissible length. Error code: ssl_error_rx_record_too_long). If I go to https://my.example.com:443/test.php then the URL redirects to https://my.example.com/test.php with no errors or problems except that my PHP prints out that the server port is 80 instead of 443.
Here's the relevant section from the conf.d/ssl.conf file (I removed what I believe are extraneous directives out and replaced the actual IP address with the word IP_ADDRESS):
Listen IP_ADDRESS:443
<VirtualHost *:443>
ServerName my.example.com
ServerAlias my
DocumentRoot "/path/to/document_root/htdocs"
Options +Indexes
</VirtualHost>
Here is the full print out of $_SERVER variable (with my server details redacted/changed to anonymous examples):
Array
(
[HTTP_HOST] => my.example.com
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 115
[HTTP_CONNECTION] => keep-alive
[HTTP_COOKIE] => PHPSESSID=randomstring_yes_I'm_that_paranoid
[PATH] => /sbin:/usr/sbin:/bin:/usr/bin
[SERVER_SIGNATURE] =>
Apache/2.2.3 (Red Hat) Server at my.example.com Port 80
[SERVER_SOFTWARE] => Apache/2.2.3 (Red Hat)
[SERVER_NAME] => my.example.com
[SERVER_ADDR] => IP_ADDRESS_1
[SERVER_PORT] => 80
[REMOTE_ADDR] => IP_ADDRESS_2
[DOCUMENT_ROOT] => /path/to/document_root/htdocs
[SERVER_ADMIN] => [email protected]
[SCRIPT_FILENAME] => /path/to/document_root/htdocs/test.php
[REMOTE_PORT] => 49178
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /test.php
[SCRIPT_NAME] => /test.php
[PHP_SELF] => /test.php
[REQUEST_TIME] => 1292273758
)
As you can see, the SERVER_PORT is 80 and $_SERVER['HTTPS'] isn't set. According to the PHP docs, I thought it was supposed to be set to a non-empty value if the PHP script is accessed via HTTPS (which is what I'm doing).
Any idea what's going on? I'm just the web developer - I don't manage this server but my server admin tells me everything is working but I would like to know why $_SERVER['SERVER_PORT'] is returning 80 instead of 443 when viewing an HTTPS URL.
EDIT: I've edited the above example to illustrate my results in printing out the entire $_SERVER variable.
EDIT 2: Trying https://my.example.com:443/test.php as suggested in the comments below does the same thing - SERVER_PORT is 80 and HTTPS isn't set (specifically trying this URL redirects to https://my.example.com/test.php).
EDIT 3: OK, I've posted what I believe is the answer to this below (TL;DR: moving the SSL directives inside the VirtualHost directive and changing that directive to reference my site using it's IP address rather than a wildcard appears to have resolved the problem).
$_SERVER['HTTPS']
... What's the value there?