Ivorde Unix/Linux/Database/Web/Mail Forum

View unanswered posts
View active topics
It is currently Sat Feb 04, 2012 10:23 pm


This forum is dedicated to Apache, Nginx, Lighttpd, Squid and other HTTP transport protocol related software

Bookmark this article:

Author Message
debuser
  Post  Post subject: Apache to Nginx Server parameters translation with php function  |  Posted: Thu Aug 26, 2010 2:47 pm

Joined: Thu Aug 06, 2009 9:48 am
Posts: 90

Offline
Save on Delicious
When ran as Apache module, PHP will get $_SERVER variables in the form that they come in the request:
Content-Type, Content-Length, X-File-Size, X-File-Name and so on.


When ran as PHP-FPM with NGINX, php will see the $_SERVER variables in a totally different way (this is because of the default passing of server parameters to fcgi scripts in nginx).

Here's how $_SERVER variables will be seen by php when ran as php-fpm:
Code:
Array ( [USER] => nobody [HOME] => / [FCGI_ROLE] => RESPONDER [SCRIPT_FILENAME] => /usr/local/www/www.site.com/public_html/site/index.php [Content-Type] => multipart/form-data [QUERY_STRING] => upload=true [REQUEST_METHOD] => POST [CONTENT_LENGTH] => 40403 [SCRIPT_NAME] => /site/index.php [REQUEST_URI] => /site/index.php?upload=true [DOCUMENT_URI] => /site/index.php [DOCUMENT_ROOT] => /usr/local/www/www.site.com/public_html [SERVER_PROTOCOL] => HTTP/1.1 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx/0.7.65 [REMOTE_ADDR] => 193.110.48.4 [REMOTE_PORT] => 9971 [SERVER_ADDR] => 192.168.1.10 [SERVER_PORT] => 80 [SERVER_NAME] => www.site.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.site.com [HTTP_ORIGIN] => http://www.site.com [HTTP_X_FILE_SIZE] => 40403 [HTTP_X_REQUESTED_WITH] => XMLHttpRequest [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_IF_MODIFIED_SINCE] => Mon, 26 Jul 1997 05:00:00 GMT [HTTP_CONTENT_LENGTH] => 40403 [HTTP_X_FILE_NAME] => nokia-6300-yahoo.jpg [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/533.17.8 (KHTML, like Gecko) Version/5.0.1 Safari/533.17.8 [HTTP_CONTENT_TYPE] => multipart/form-data [HTTP_REFERER] => http://www.site.com/site/index.php [HTTP_ACCEPT] => */* [HTTP_ACCEPT_LANGUAGE] => en-us [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => keep-alive [PHP_SELF] => /site/index.php [REQUEST_TIME] => 1282822862 )


Note the HTTP_CONTENT_TYPE, HTTP_X_FILE_SIZE, HTTP_X_FILE_NAME and other HTTP_* variables.

Below is a simple php function that will regulate these header values into apache like ones. I'm figuring that it's easier to implement it rather than changing a whole application.
Code:
    function emu_getallheaders() {
        $replace_array = array('CONTENT_TYPE' => 'Content-Type',
                        'CONTENT_LENGTH' => 'Content-Length',
                        'X_FILE_SIZE' => 'X-File-Size',
                        'X_FILE_NAME' => 'X-File-Name');
        foreach($_SERVER as $h=>$v) {
            $h = str_replace("HTTP_", "", $h);
            $h = $replace_array[$h];
            $headers[$h] = $v;
        }
        return $headers;
}

The $headers variable will be an asociative array containing the header attribute name as key and the header attribute value as array value. The $replace_array array inside the function can be changed to contain more translations. I just needed these four.


Top
Display posts from previous:  Sort by  
Print view

Topics related to - "Apache to Nginx Server parameters translation with php function"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Attachment(s) Nginx + apache (for PHP) with real IP addresses in logs

designeru

0

2128

Tue May 18, 2010 4:49 pm

designeru View the latest post

There are no new unread posts for this topic. Converting PhpBB-SEO Apache RewriteRule to Nginx rewrite

debuser

0

18420

Tue Feb 23, 2010 12:00 pm

debuser View the latest post

There are no new unread posts for this topic. How can I see what virtual hosts are currently configured on my Apache server ?

LaR3

0

581

Sun Feb 07, 2010 5:04 pm

LaR3 View the latest post

There are no new unread posts for this topic. How to test deflate/gzip compression on a HTTPS (HTTP over SSL) Apache server

debuser

0

3680

Tue Aug 03, 2010 10:30 am

debuser View the latest post

There are no new unread posts for this topic. Apache - Restricting "Server" information in HTTP response header with ServerTokens

debuser

0

196

Thu Nov 10, 2011 1:39 pm

debuser View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC + 2 hours [ DST ]

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
DAJ Glass 2 template created by Dustin Baccetti

phpBB SEO