Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am planning to switch my website (drupal 6.25) from apache to nginx. i have prepared everything for nginx and tested it on port 81. it is working fine. and now i changed listen from 81 to 80 and stop apache and start nginx. the website starts giving

504 Gateway Time-out nginx/0.8.54

and serves nothing :( my nginx server is

server {
        listen   80 backlog=128;
        root /var/www/web1/htdocs;
        index index.php index.html index.htm;        

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

        access_log /var/log/nginx.web1.log;
        error_log /var/log/nginx.web1.error.log error;
        location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
                rewrite ^/favicon.ico$ /sites/all/themes/sky/favicon.ico break;
                access_log        off;
                expires           30d;
        location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        #fastcgi_pass; #I have tried this option as well
        fastcgi_pass  unix:/tmp/php.socket;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/web1/htdocs/$fastcgi_script_name;

and the nginx.conf contains:

user www-data;
worker_processes 5;
pid /var/run/;

events {
        worker_connections 64;
        # multi_accept on;

http {

        # Basic Settings

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        keepalive_requests      20;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        # Logging Settings

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        # Gzip Settings

        gzip on;
        gzip_static       on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        # Virtual Host Configs

 include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

#mail {
#       # See sample authentication script at:
#       #
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }

any idea of what is wrong? or how can i fix it?
Thanks a lot for your help

share|improve this question
The error says "Gateway timeout" yet you're not showing any configuration of PHP. Please provide this or people won't be able to help you much. – Martin Fjordvald May 3 '12 at 12:08
in php.ini, i have request_terminate_timeout=30s max_execution_time = 30 memory_limit = 2048M default_socket_timeout = 60 what else you might need from php.ini? – Alaa Alomari May 3 '12 at 12:42
Anything in /var/log/nginx/access.log or /var/log/nginx/error.log? – pjmorse May 3 '12 at 13:30
Mostly interested in how you spawn php, I was suspecting that you didn't at all but I didn't want to put an answer until I knew it. Seems vartec didn't mind though so follow his advice. – Martin Fjordvald May 3 '12 at 14:18
@pjmorse: nothing wrong at all in the error log. – Alaa Alomari May 5 '12 at 9:27
up vote 1 down vote accepted

You're trying to connect to PHP Fast-CGI on unix:/tmp/php.socket, but you're not running PHP Fast-CGI daemon. PHP-FPM is a separate daemon and nginx will not spawn it automatically.

See PHP documentation on deploying FastCGI Process Manager (FPM) and HOWTO for installing Nginix + PHP-FPM on Ubuntu

If you're using standard install, you're most likely will have a service named php-fpm or php5-fpm, which you should start and add to list of services started automatically.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.