nginx configuration tip

This is something I run into while deploying this site.

I have created a separate controller for post categories that returns post categories as JSON for jQuery Tokeninput providing autocompletion when selecting the categories.

I had the site and this specific functionality working nicely on the local environment, but when deploying to the production server, I was not able to set a post category. Checking Firebug didn't really provide much information, it just showed a 404 status for the request. In the nginx error log I noticed that it was trying to serve a file, which was not found.

After some debugging I realized that the following location statement that's used for configuring specific aspects of the asset pipeline was actually also catching json requests:

location ~* \.(ico|js|css|png|jp?g|gif)

where the js part catches both js and json. The fix for that was to change the regular expression to the following

location ~* \.(ico|js$|css|png|jp?g|gif)

which only matches file names that end with js.