Nginx config not quite right?


(James) #1

I've got it all working OK apart from the wysiwyg's plugins.  I can open the wysiwyg to add text and save it fine, but when I click on the icon to insert an image I get a pop up window with this URL:

 

<mydomain>/__fudge/wysiwyg/plugins/matrix_insert_image/insert_image_frames.php?f_imageid=0&f_align=&f_width=&f_height=&f_alt=&f_title=&f_longdesc=&f_horiz=&f_vert=&f_border=0&f_image_class=&f_image_id=&editor_name=bodycopy_194_content_type_wysiwyg_211&in_popup=0

 

(Looks the same as one I have with Apache that works)

 

BUT... in the pop up window it just says:

 

File not found.

 

Same goes for other insert stuff like the embed video.  The files are definitely there and I can access them on the Linux command line.  File permissions and locations are same as on another live box running Matrix (with Apache not nginx) that works fine.

 

I think it might be my nginx config?   (based on http://forums.squizsuite.net/index.php?showtopic=5212) :

 

server {         listen       80;
        root   /var/www/squiz_matrix/core/web;

        # Logging
        access_log  /var/log/nginx/mysite.access.log;
        error_log  /var/log/nginx/mysite.error.log;

        # Save the original script URI in a variable before we rewrite it (we need to
        # pass the original URI onto FastCGI later for Matrix's sake).
        #
        set $orig_uri $uri;

       location / {
                index  index.php;

                # Rewrite ALL requests to Matrix's index.php file
                rewrite  ^(.*)$  /index.php  last;
         }

        # access_log off; prevents logging of these hits to the access log (you may or may not want this)
        location /__data/    { alias /var/www/squiz_matrix/data/public/; }
        location /__lib/        { access_log off; alias /var/www/squiz_matrix/core/lib/; }
       

        location /__fudge/      {
                                access_log off;
                                alias /var/www/squiz_matrix/fudge/;
                                           }



        location ~ .php$ {
                fastcgi_pass  unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;

                fastcgi_param   SCRIPT_FILENAME /var/www/squiz_matrix/core/web/$fastcgi_script_name;
                # Modified for Matrix
                fastcgi_param   PHP_SELF        $request_uri;
                fastcgi_param   PATH_INFO       $orig_uri;
                fastcgi_param   SCRIPT_NAME     $orig_uri;

                # Some defaults
                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  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;

                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;

                include fastcgi_params;
        }
}
 

The fudge bit in red might be missing something?  Apart from that it all seems to work great.

 

Any help appreciated.


(James) #2

After some more testing it seems to be only .php files that come up with "File not found".  Files with other extensions (i.e. .txt) load up OK in the browser when put in the same  <mydomain>/__fudge/wysiwyg/plugins/matrix_insert_image/ directory.  So not sure what's going on, maybe one of the settings in the last location is wrong?


(Hamish Forbes) #3

Hi,

 

Obviously Squiz don't officially support running Matrix via nginx and php-fpm... however!

This should work: https://gist.github.com/hamishforbes/8470813

It will catch all the php scripts in lib / fudge / data etc

 

Drop the 'matrix-common' include into your nginx conf.d directory (without a .conf extension).

Then just set the $matrix_root and $fcgi_paths and include matrix-common in any server block you want to connect to Matrix.

 

The only thing you should have to edit in the matrix-common include is the expiry times for static files.

Although thinking about it that could be abstracted out to a variable too...

 

Good luck!


(James) #4

Very much appreciated.  I'll give it a go.

 

At work we use Apache Pre-fork for Squiz Matrix, but then those servers have plenty of memory and CPU power.  This is for my own Raspberry PI which I use to test new stuff. Matrix works really well on it despite having just 256M of memory and a tiny 700Mhz processor.   Editing can be a bit slow but for experimenting with alternative architectures like Nginx it's great :)

 

http://home.froddy.co.uk/home (if it's broke it's probably me setting up this new nginx config).  So far it's been up and running no problems (except the WYSIWYG issue) since Christmas.

 

Thanks again.


(James) #5

Cool, I've now added the Nginx config as per https://gist.github....hforbes/8470813  - it works! :)

 

I did have to change one minor thing.  I moved the   "include  fastcgi_params;"  line to be above the block bespoke fastcgi params or it got overridden by the Nginx defaults (could amend those of course if just running Matrix I guess?).

 

# Pass everything else to matrix handler location / {
    include         fastcgi_params;
    fastcgi_pass    $fcgi_path;
    fastcgi_param   SCRIPT_FILENAME  $document_root/core/web/index.php$fastcgi_script_name;
#    include         fastcgi_params; #  must be above last line or SCRIPT_FILENAME will be overridden with default params value
}

 

Thanks again!


(James) #6

I tried to edit the expiry times but it just messed up the pages and the admin interface.  For example to add an expiry for the CSS files of 30 days I dropped this in under the existing deny location blocks:

# deny .inc, .FFV and CVS location ~ \.inc$ {
    deny  all;
}
location ~ /(CVS|\.FFV)/ {
    deny all;
}

location ~ \.css$ {
expires 30d;
}

 

Not sure where else to put it?