Welcome! Log In Create A New Profile


Fwd: Wrong $server_name variable (FastCGI phpCAS problem)

Huan Truong
March 24, 2012 12:46PM
Hi all,

We were trying to migrate Wordpress multisite from Apache to nginx and
had a pretty frustrated time trying to figure out why our our CAS
authentication did not work correctly with our setup.

In our setup, we have a whole bunch of sub-domains hosted at:


So we let nginx listening as follow

server_name sites.example.edu *.sites.example.edu *.example.edu;

When we tried our CAS authentication, only the CAS requests originated
from sites.example.edu worked, none of the requests originated from
*.sites.example.edu worked and resulted in a infinite redirect. I dug
in a bit and found out that PHP was requesting a wrong return service
url [1] (on Apache the return service url that PHP constructed is
mysite.sites.example.edu, while with nginx it is sites.example.edu).
It turned out that phpCAS used SERVER_NAME to determine the return
service URL, and nginx passed to PHP the wrong answer.

The fastcgi configuration is as follow:

fastcgi_param  SERVER_NAME        $server_name; # returns
sites.example.edu on http://mysite.sites.example.edu

It can be temporarily fixed by setting

fastcgi_param  SERVER_NAME        $host; # returns
mysite.sites.example.edu on http://mysite.sites.example.edu

But in this case I feel the $server_name should take the value of
mysite.sites.example.edu when the browser requests
mysite.sites.example.edu instead of sites.example.edu, the first value
it found on the server_name directive.

[1]: https://wiki.case.edu/Central_Authentication_Service#Detailed_overview

code ninja | tnhh.net | @huant

nginx mailing list
Subject Author Posted

Fwd: Wrong $server_name variable (FastCGI phpCAS problem)

Huan Truong March 24, 2012 12:46PM

Re: Wrong $server_name variable (FastCGI phpCAS problem)

Brian Akins March 24, 2012 10:08PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 107
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready