# Fwd: Wrong $server\_name variable (FastCGI phpCAS problem)

**URL:** <https://www.ruby-forum.com/t/fwd-wrong-server-name-variable-fastcgi-phpcas-problem/218217>\
**Category:** NGINX\
**Created:** [March 24, 2012, 5:45pm UTC](https://www.ruby-forum.com/t/fwd-wrong-server-name-variable-fastcgi-phpcas-problem/218217 "2012-03-24T17:45:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 24, 2012, 5:45pm UTC](https://www.ruby-forum.com/t/fwd-wrong-server-name-variable-fastcgi-phpcas-problem/218217/1 "2012-03-24T17:45:59Z")

</div>

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:

\*.sites.example.edu

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](https://wiki.case.edu/Central_Authentication_Service#Detailed_overview) (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](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](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.

–  
code ninja | [tnhh.net](http://tnhh.net) | @huant

---

<div class="post-metadata">

**Author:** ![Huan\_Truong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@Huan\_Truong](https://www.ruby-forum.com/u/Huan_Truong)\
**Post date:** [March 25, 2012, 4:07am UTC](https://www.ruby-forum.com/t/fwd-wrong-server-name-variable-fastcgi-phpcas-problem/218217/2 "2012-03-25T04:07:16Z")

</div>

On Mar 24, 2012, at 12:45 PM, Huan Truong wrote:

> 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.

That _is_ what $host does:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com
