0

I'm trying to test nginx on Dreamhost following the instructions in the wiki, but going to any page except for the front page results in a 404 error: http://wiki.dreamhost.com/Nginx#Drupal.

Certain things are assumed, and from that assumption I cannot tell if they apply to what I'm trying to do or not. I'm guessing its some kind of clean URL based error.

For example, /home/YOURUSER/nginx/example.com/drupal.conf; my path is /home/YOURUSER/example.com/drupal.conf.

I'm assuming at this point that is not the issue. I've tried various things including just putting in what appears to be the bare minimum to no effect:

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

Any pointers would be helpful. I'd like to get this working with Boost.

I also attempted to use this: http://wiki.nginx.org/Drupal#Not_So_Simple.

Disabling clean URLs allows me to log in, and Drupal states that clean URLs are not enabled.

1
2

This is what I use (with Drupal 6 and Boost), most is self explanatory but I added additional comments here and there:

server {
        listen          80;
        server_name     IP.NR example.com www.example.com;  # Multiple hostnames seperated by spaces
        root            /path/to/drupal; # Replace this
        charset         utf-8;
        access_log  /var/log/nginx/example.com.access.log  combined;
        error_log   /var/log/nginx/example.com.error.log;

        index  index.php;

        if ($host ~* (^example.com|www.example2.com)) { # Redirect to www.example.com
                rewrite ^(.*)   http://www.example.com$1 permanent;
        }

    ## 6.x starts
        location / {
                #rewrite ^/(.*)/$ /$1 permanent; # remove trailing slashes - disabled
                try_files $uri @cache;
        }

        location @cache {
                if ( $request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_cookie ~ "DRUPAL_UID") {
                        return 405;
                }
                error_page  405 = @drupal;
                add_header  Expires "Tue, 24 Jan 1984 08:00:00 GMT";
                add_header  Cache-Control "must-revalidate, post-check=0, pre-check=0";
                add_header  X-Header "Boost Citrus 1.9";
                charset         utf-8;
                try_files   /cache/normal/$host${uri}_$args.html /cache/$host${uri}_$args.html @drupal;
        }

        location @drupal {
                ###
                ### now simplified to reduce rewrites
                ###
                rewrite ^/(.*)$  /index.php?q=$1 last;
        }

        location ~*
        (/\..*|settings\.php$|\.(htaccess|engine|inc|info|install|module|profile|pl|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(Entries.*|Repository|Root|Tag|Template))$
        {
                deny all;
        }

        location ~* /files/.*\.php$ {
                return 444;
        }
        location ~* /themes/.*\.php$ {
                return 444;
        }

        location ~ \.php$ {
                try_files $uri @drupal;           #check for existence of php file
                fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; 
                include /etc/nginx/conf.d/php_fpm; # Includes config for PHP-FPM (see below)
        }

        location ~ \.css$ {
                if ( $request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_cookie ~ "DRUPAL_UID") {
                        return 405;
            }
                error_page 405 = @uncached;
                #access_log     off;
                expires         max; #if using aggregator
                add_header      X-Header "Boost Citrus 2.1";
            try_files   /cache/perm/$host${uri}_.css /cache/$host${uri}_.css $uri =404;
        }

        location ~ \.js$ {

                if ( $request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_cookie ~ "DRUPAL_UID") {
                    return 405;
                }
                error_page 405 = @uncached;
                #access_log  off;
                expires  max; # if using aggregator
                add_header X-Header "Boost Citrus 2.2";
            try_files /cache/perm/$host${uri}_.js /cache/$host${uri}_.js $uri =404;
        }

        location @uncached {
                #access_log  off;
                expires  max; # max if using aggregator, otherwise sane expire time
        }

        location ~* /files/imagecache/ {
                #access_log         off;
                try_files $uri @drupal;  #imagecache support - now it works
        }

        location ~* /files/backup_migrate/ {
                deny all;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
                #access_log  off;
            expires          14d;
            try_files $uri = 404;
        }


        location ~* \.xml$ {
                if ( $request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_cookie ~ "DRUPAL_UID") {
                        return 405;
                }
                error_page 405 = @drupal;
                add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";
                add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
                add_header X-Header "Boost Citrus 2.4";
                charset utf-8;
                types { }
                default_type application/rss+xml;
                try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html /cache/$host${uri}_.xml $uri @drupal;
        }

        location ~* /feed$ {
                if ( $request_method !~ ^(GET|HEAD)$ ) {
                        return 405;
                }
                if ($http_cookie ~ "DRUPAL_UID") {
                        return 405;
                }
                error_page 405 = @drupal;
                add_header Expires "Tue, 24 Jan 1984 08:00:00 GMT";
                add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
                add_header X-Header "Boost Citrus 2.5";
                charset utf-8;
                types { }

                default_type application/rss+xml;
                try_files /cache/normal/$host${uri}_.xml /cache/normal/$host${uri}_.html /cache/$host${uri}_.xml $uri @drupal;
        }

#        error_page  404              /index.php;

        # redirect server error pages to the static page /50x.html
        #
#        error_page   500 502 503 504  /50x.html;
#        location = /50x.html {
#            root   html;
#        }


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

        location /server-status {
                stub_status on;
                access_log off;

        }

     }

I'm using PHP-FPM (which is included in PHP 5.3 but I'm using 5.2) so I also include this file (...conf.d/php_fpm)

        fastcgi_pass   127.0.0.1:9000;    #php-fpm listening on port 9000
        fastcgi_index  index.php;
        fastcgi_param  QUERY_STRING   $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE   $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;

        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  SERVER_PROTOCOL    $server_protocol;

        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

        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;

        # PHP only, required if PHP was built with --enable-force-cgi-redirect
        fastcgi_param  REDIRECT_STATUS    200;

        fastcgi_connect_timeout         60;
        fastcgi_send_timeout            180;
        fastcgi_read_timeout            180;
        fastcgi_buffer_size             128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size   256k;
        fastcgi_temp_file_write_size    256k;
#   fastcgi_intercept_errors        on;

Just ask if you have any questions about specificities.

0

Even though it seemed odd, I created a nginx/site.com and put the .conf there. I am accustomed to .htaccess, but apparently this file does not belong even in the same dir so in the end it was just a silly mistake with where I put the .conf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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