Using nginx + php-fpm so it doesn't use htaccess. Is there any doc on how to get it work in nginx environment. And i also can't get the FAST 404 to work,
already copy the follow code at the bottom of my settings.php but no lucky, doesn't work. Adv CSS/JS Agg - Asynchronous Mode Set to FALSE.
// List of extensions for static files
$exts = 'txt|png|gif|jpe?g|shtml?|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp|xml';
// It is not an imagecache path, which we allow to go through Drupal
if (!strpos($_SERVER['QUERY_STRING'], 'imagecache') && !strpos($_SERVER['QUERY_STRING'], '/advagg_')) {
// It is not our main feed page
if ($_SERVER['QUERY_STRING'] != 'rss.xml') {
// Is it a static file?
if (preg_match('/\.(' . $exts . ')$/', $_SERVER['QUERY_STRING']))
// Just send a 404 right now ...
{
header('HTTP/1.0 404 Not Found');
print '';
print '404 Not Found';
print '
Not Found
';
print '
The requested URL was not found on this server.
';
print '';
exit();
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | advagg-1116618-23.patch | 704 bytes | mikeytown2 |
| #21 | advagg-1116618-21.patch | 878 bytes | mikeytown2 |
| #15 | advagg-1116618-15.patch | 701 bytes | mikeytown2 |
| #2 | nginx.zip | 3.06 KB | spacereactor |
Comments
Comment #1
mikeytown2 commentedhttp://wiki.nginx.org/HttpGzipStaticModule should do the gzip stuff. The other rules has to do with the expiration time and changing it from the default 2 weeks to 1 year.
I use this URL as a the test for fast 404s
example.com/sites/default/files/advagg_css/css_missing_0.cssI then check for the X-AdvAgg header. If that is set in the request then I know missing files are correctly being routed to the advagg handler. My guess is you have a rule for the files directory in your nginx config. What you need to do is look for the imagecache rules and adapt them for the advagg_css and advagg_js directories.
Comment #2
spacereactor commentedi got the async mode working. I need to manually add "sites/default/files" since i using private setting at admin/settings/advagg/config
I attach my nginx.conf and domain.com in a zip file if anyone need it.
Using most of my nginx conf setting from perusio. THANK you perusio!!
https://github.com/perusio/drupal-with-nginx
Comment #3
spacereactor commentedComment #4
spacereactor commentedhow you purge the cache css and js? i try to flash all cache but all the files in advagg_css and advagg_js remain, i need to manually delete the files in advagg_css and advagg_js. Is that how it work or my nginx setting wrong
Comment #5
mikeytown2 commentedI use the similar logic in this module for what is used in core in D7. Aggregates do not get flushed till they haven't been used in 30 days drupal_delete_file_if_stale(). Let me know if you have any more questions :)
Comment #6
spacereactor commentedthank for your info.
Comment #7
omega8cc commentedMy working configuration supporting advagg in Nginx:
https://github.com/omega8cc/nginx-for-drupal/blob/master/aegir/conf/ngin...
Comment #8
mikeytown2 commentedAfter testing on a lot of browsers I brought back etags. I don't think nginx has full etag support out of the box, so I would turn back on Last-Modified; they accomplish the same goal.
http://drupalcode.org/project/advagg.git/commitdiff/c132a7e45375def56d41...
Comment #9
spacereactor commentedI have set private file to be "sites/default/private" and advagg to "sites/default/public" for publlic access css and js
But it keep create file at /sites/default/public/default/advagg_css and js
I can't get aboves to work, what do i mess up again....
Comment #10
omega8cc commentedRight, there is an experimental module for Nginx: http://mikewest.org/2008/11/generating-etags-for-static-content-using-nginx but we should stay with Last-Modified probably.
Thanks for the update!
Comment #11
omega8cc commented@spacereactor you could try this, as you don't need any rewrite, IMO:
Comment #12
spacereactor commented#9 solution for /sites/default/public/default/advagg_css and js is by setting the path to "sites" for your advadd folder location.
Goto admin/settings/advagg/config -> Use a different directory for storing advagg files: -> sites
you may need to create advagg_css & advagg_js folder, but inputing sites as your path, it will now link to your /sites/default/advagg_css and js folder or if you using a subdomain name or other domainname, it will automatic link to your /sites/subdomain/advagg_css and js folder or /sites/other-domainname/advagg_css and js folder.
Hope this help someone.
Comment #13
crea commentedI remember reading about Etags in Nginx and the program author said that it's not supported in Nginx because it essentially duplicates last-modified.
Comment #14
Peter Bowey commentedEtag can be useful for static and dynamic content, typically - when the modify time is not known. Etag is more granular than 'Last-Modified'.
'Last-Modified' is typically accurate to the second, and only measures change along the axis of time. Touching [date/time] a file does not change it’s content, but would force a cache miss when the cache is based on nothing but it's time-stamp ['Last-Modified'].
In contrast, Etags are 'content-based' identifiers that provide a mechanism for confirmation that the content of the file you’re reading is accurate, regardless of various delivery deployment methods on the server.
Some thoughts: It is not a bad practice to rely entirely on 'Last-Modified' when serving truly static content. In this case, the correct use of 'Cache-Control' and 'Expires' headers, will allow client browsers and upstream proxies to cache the static content correctly.
see http://mikewest.org/2008/11/generating-etags-for-static-content-using-nginx
HTTP 1.1 introduces a new kind of validator called the ETag. ETags are unique identifiers that are generated by the server and changed every time the representation does. Because the server controls how the ETag is generated, caches can be posotive that if the ETag matches when they make a If-None-Match request, the representation really is the same.
Almost all caches use Last-Modified times in determining if an representation is fresh; However, ETag validation is also becoming more prevalent.
Most modern Web servers will generate both ETag and Last-Modified headers to use as validators for static content (files) automatically; you won’t have to do anything. However, they don’t know enough about dynamic content (like CGI, ASP or database sites) to generate them; see Writing Cache-Aware Scripts -> http://www.mnot.net/cache_docs/#SCRIPT.
[nginx.conf:] config settings for advagg module see -> http://drupal.org/project/advagg
Nginx STATIC 'etag' support
See: https://github.com/kkung/nginx-static-etags/
Compile this into nginx (source)
Nginx 'etag' [nginx.conf] Sample Usage: (for above 'static etags')
Nginx DYNAMIC 'etag' support
See: https://github.com/kali/nginx-dynamic-etags
Per Nginx DYNAMIC 'etag' 'readme':
Etags Final Notes / Warning: The ETag format for Apache 1.3 and 2.x is 'inode-size-timestamp', please be sure to NOT include the 'inode'. Simply override the default and only use modify time [timestamp] and size [size] only. eg: "
FileETag MTime Size"This means that the same static object across cluster hosts can have the same etag! The same logic will apply for using Etags with Nginx. See code sample above:
Comment #15
mikeytown2 commentedAdded in the configuration from #11 into the readme.
Comment #17
superfedya commented>Added in the configuration from #11 into the readme.
nginx: [emerg] "location" directive is not allowed here in /usr/local/nginx//conf/nginx.conf:91
nginx: configuration file /usr/local/nginx//conf/nginx.conf test failed
Line 91: location ~* advagg_(?:css|js)/ {
Any suggestion?
Thanks
Comment #18
mikeytown2 commentedBased off of the recommendations in the CDN module (#974350-57: Far Future setting for Origin Pull mode), these are the headers we need to set/unset in nginx. The CDN module could use these rules translated over as well.
These changes have been committed to AdvAgg in #1334460-12: Slow Loading CSS Aggregate
Comment #19
omega8cc commentedHere is modified Nginx config:
BTW:
expires max;setsmax-ageforCache-Controlto 10 years, automatically - see http://wiki.nginx.org/NginxHttpHeadersModule#expiresComment #20
omega8cc commented@superfedya - see http://wiki.nginx.org/NginxHttpCoreModule#location
In short,
locationdirective is expected insideserverdirective, but it is Nginx basics, not really discussed in this issue.Comment #21
mikeytown2 commentedI'll add the code without etags to the readme. Apache by default has etags turned on, I believe nginx has it off by default. I'll add in a note about etags in the comment block at the top. I believe
add_header ETag "";doesn't do what we want in this case.Comment #22
omega8cc commentedI just translated it to Nginx config literally, but you are right that Nginx has no (default) support for
ETagheader. But you don't need any extraHttpHeadersMoreModuleto unset most headers. Theadd_header SomeHeader "";trick does the same - at least for headers we want to unset.Comment #23
mikeytown2 commentedSounds good! Thanks for your help with this. The following patch has been committed.