Nginx - Treats PHP as binary
https://stackoverflow.com/questions/1041315
Question
We are running Nginx+FastCgi as the backend for our Drupal site. Everything seems to work like fine, except for this one url. http:///sites/all/modules/tinymce/tinymce/jscripts/tiny_mce/plugins/smimage/index.php
(We use TinyMCE module in Drupal, and the url above is invoked when user tries to upload an image)
When we were using Apache, everything was working fine. However, nginx treats that above url Binary and tries to Download it. (We've verified that the file pointed out by the url is a valid PHP file)
Any idea what could be wrong here?
I think it's something to do with the NGINX configuration, but not entirely sure what that is.
Any help is greatly appreciated.
Config: Here's the snippet from the nginx configuration file:
root /var/www/;
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
error_page 404 index.php;
location ~*
\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$
{
deny all;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
access_log off;
expires 7d;
}
location ~* ^.+\.(css|js)$ {
access_log off;
expires 7d;
}
location ~ .php$ {
include /etc/nginx/fcgi.conf;
fastcgi_pass 127.0.0.1:8888;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
location ~ /\.ht {
deny all;
}
OTHER TIPS
If that didn't do it, also be sure that you have fastcgi running on port 8888. You can check that with:
netstat -la | grep :8888
You're okay if you get a response like:
tcp 0 0 localhost:9000 *:* LISTEN
Or try the following and look for which port it is listening on:
netstat -la | grep LISTEN
Maybe the php file is running but generating a binary file. Is this script generating an image? Hard to tell without seeing some config.