After a week of “502 Bad Gateway” error on blog.feevy.com, it was time to dive in our new Nginx toy on Feevy server and understand what happened.

First, Nginx is not like Apache or Lighttpd, it doesn’t support FastCGI by default. So, you need to be sure you’ve compiled the fcgi module with your PHP installation.

On Centos, to compile a new PHP, just launch: /scripts/easyapache

Then you’ll need to launch the FastCGI process, download this FastCGI script, place it in /usr/local/bin, and add it to your init.d.

At the end, you just need to configure your php server in nginx, that would be the most simple part:

  server {
      listen 80;
      server_name     blog.feevy.com;
      index           index.php;
      root            /home/wwwfeev/blog;

      if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?q=$1  last;
        break;
      }

      location ~ .php$ {
         fastcgi_pass  127.0.0.1:9999;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_NAME $fastcgi_script_name;
         fastcgi_param REQUEST_URI $request_uri;
         fastcgi_param DOCUMENT_URI $document_uri;
         fastcgi_param DOCUMENT_ROOT $document_root;
         fastcgi_param REMOTE_ADDR $remote_addr;
         fastcgi_param REMOTE_PORT $remote_port;
         fastcgi_param SERVER_ADDR $server_addr;
         fastcgi_param SERVER_PORT $server_port;
         fastcgi_param SERVER_NAME $server_name;
         fastcgi_param SCRIPT_FILENAME  /home/wwwfeev/blog/$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;
      }
  }

About alx

No Comments

Be the first to start a conversation

Leave a Reply

  • (will not be published)