中文博客 (10) 美国陆军 (8) 部队生活 (7) English Blog (4) PHP (4) World of Warcraft (4) XML (2) IT (1) Network (1) Nginx (1) OIF (1) Rogue (1) Win 7 (1) 伊拉克 (1) 假期 (1) 笑话 (1)

Wednesday, April 10, 2013

Nginx document_root variable

I have setup a Nginx/PHP-PFM server recently so that I can move my webpage from LAMP to LEMP. After importing my code over to the new server, all included Javascript and CSS files stopped working. It disappeared from the source code.

I spent sometime searching Nginx $_SERVER['DOCUMENT_ROOT'] in Google, most paged I found were talking about how to configure Nginx document root, which was not what I was looking for.

Both configuration are relatively similiar as shown below:

     Apache configuration: DocumentRoot /var/www/

     Nginx configuration: root /var/www/

However, same setup gives a different result.


Without a doubt, I believe this is a problem of how Apache and Nginx define document_root variable. I create a test file just to print_r $_SERVER variables' values, and I found out:

In Apache:

      [DOCUMENT_ROOT] => /var/www/                       (This is the default value of root configuration)

But in Naginx:

      [DOCUMENT_ROOT] => /var/www                        (Again, I am using the default location as an example)

As we all know, / differentiates sub directory or part of file name. A simple problem to fix.

Hope this helps someone

--------------------------
个人网页(Personal Website):http://xiangstan.com
Facebook:http://www.facebook.com/xiangs.tan

No comments:

Post a Comment