Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to the nginx configuration #133

Closed
wants to merge 25 commits into from
Closed

Enhancements to the nginx configuration #133

wants to merge 25 commits into from

Conversation

aitte
Copy link
Contributor

@aitte aitte commented Feb 24, 2013

Implementations for most of the open issues in the issue tracker. These changes are all in use on various production servers that I administer and have been very well tested for months. I also added a few new features that we are using on our servers, which I am sure will come in very handy for most people. Code review should be simple since I've limited things to one feature per commit. Enjoy!

alrra and others added 19 commits February 12, 2013 16:35
…es around, breaking the intended apache log format compatibility)
… out instead, that way it will align them to CPU cache lines for greater performance
…s for 10 minutes rather than constantly re-negotiating
…and blocking requests that lack the Host header
…tty much 100% of sites; avoids filling error logs with 404 for commonly sought yet commonly missing files such as robots.txt, favicon.ico and so on
@paulirish
Copy link
Member

Nice work! this is awesome.

the font/opentype is invalid but has pretty rich justification. it's in some commit messages back in blame if you want back a bit. so I don't think we'll change that.

the rest looks good, though i'm not too sharp with nginx.. can someone else take a look?

@aitte
Copy link
Contributor Author

aitte commented Feb 24, 2013

Interesting, I'd love to know what's up with the font/opentype since "font/*" is an invalid mime type.

Maybe we should settle this with a battle, like real men.

http://www.googlebattle.com/?domain=%22font%2Fopentype%22&domain2=%22application%2Fx-font-opentype%22&submit=Go%21

Anyway, yeah I'd love to know what's up with this and if there's some good browser-quirk reason to use the invalid media type.

@paulirish
Copy link
Member

quick blame search turned up
e9ac74d

i thought we had more detail than that though.

ah i see the recent h5bp/html5-boilerplate#1317

see the old h5bp/html5-boilerplate#273

On Sun, Feb 24, 2013 at 2:42 PM, aitte notifications@github.com wrote:

Interesting, I'd love to know what's up with the font/opentype since
"font/*" is an invalid mime type.

Maybe we should settle this with a battle, like real men.

http://www.googlebattle.com/?domain=%22font%2Fopentype%22&domain2=%22application%2Fx-font-opentype%22&submit=Go%21

Anyway, yeah I'd love to know what's up with this and if there's some good
browser-quirk reason to use the invalid media type.


Reply to this email directly or view it on GitHubhttps://github.com//pull/133#issuecomment-14017973.

@aitte
Copy link
Contributor Author

aitte commented Feb 24, 2013

Ahh, anyone with Chrome out there that can verify that Chrome understands application/x-font-opentype? It should, because it follows the law of "thou shalt not invent invalid mime types" and perfectly describes that it's a font and that it's of the OpenType sexuality.

application/font-woff (registered)
application/x-font-ttf (not registered but established as the standard)
application/x-font-opentype (not registered but established as the standard)

Now if only those darn ttf and otf folks could get their types registered, that'd be nice.

@paulirish
Copy link
Member

chrome wont have a problem with any of them,
but it might barf into the console. that's all i wanted to avoid.

On Sun, Feb 24, 2013 at 3:07 PM, aitte notifications@github.com wrote:

Ahh, anyone with Chrome out there that can verify that Chrome understands
application/x-font-opentype? It should, because it follows the law of "thou
shalt not invent invalid mime types" and perfectly describes that it's a
font and that it's of the OpenType sexuality.

application/font-woff (registered)
application/x-font-ttf (not registered but established as the standard)
application/x-font-opentype (not registered but established as the
standard)

Now if only those darn ttf and otf folks could get their types registered,
that'd be nice.


Reply to this email directly or view it on GitHubhttps://github.com//pull/133#issuecomment-14018434.

@@ -0,0 +1,29 @@
# Looks for common abusive programs and sets $is_crawler to 1 if found.

This comment was marked as abuse.

This comment was marked as abuse.

@vendruscolo
Copy link
Contributor

To me the Nginx part is ok. The quality of comments also improved, which is a great thing.

nginx only supports matching a single location-block before it stops execution, so the rule would have to go into the location-block that passes .php files over to FastCGI, and by that point it's too much of a hassle. modern browsers know not to cache .php files anyway, so let's simply remove the file extension.
@aitte
Copy link
Contributor Author

aitte commented Feb 25, 2013

@amenadiel: I know that you don't need server_name "" because it's the new default, but it's better to be explicit about it in case someone runs an older version, and even on the new version it aids in helping people understand what the server-block is matching (in this case, the empty "" name catches empty/missing "Host", and the default_server catches invalid hosts).

As for the bad-guys list, I agree that it'd be a nice feature to add to the other web servers too if someone wants to port it. However, I do not recommend the 5G blacklist that you linked to. Mine is the result of a lot of experience with what user-agents are out there, including only the absolutely most common ones, in order to be as light-weight as possible (remember that this runs on every HTTP request). The 5G blacklist is a crude list of various query-URLs that people might be trying when they are trying SQL injection attacks and such, and scanning for that is not the job of the web server. There are much more efficient mods like mod_security to deal with that (and that module also exists for nginx). Or the best protection of all: Common sense; don't write web applications with SQL injection vulnerabilities - sanitize user input. No heavy mods/scanners/filters needed! ;-)

If the bad-guys feature was extended to other web servers, then I suggest maintaining my approach, which is: Less is more. Aim for the big guys, to avoid slowing down the server with a massive list of 1200 user agents (the same author that created the "5G blacklist" proudly has a list of 1200 bad user agents, most of which come from the 90s and are never seen these days, heh).

The other part of my approach is acknowledging the fact that trying to block all bad tools is futile. The really good ones all fake their user-agent. Instead, we shoot for the script kiddies - and the rules are designed to catch the vast majority of newbies while still being extremely light weight. We cannot stop a determined attacker from running their request with a spoofed agent, but by aiming for the most popular tools, we cut out a very good chunk without even hurting web server performance.

And above all: The list is designed never to give any false positives. I'd rather let a few less common abuse tools through, than block a single legitimate visitor or search engine robot by having overly broad rules.

@aitte
Copy link
Contributor Author

aitte commented Feb 25, 2013

By the way, anyone with Chrome that could check if application/x-font-opentype makes it log a warning in the error console?

I don't use Chrome, nor do I want it on my system. ;-)

@alrra
Copy link
Member

alrra commented Feb 25, 2013

chrome ... might barf into the console

@paulirish It still does.

@aitte thanks for the pull request! (just one recommendation: in the future try to separate related commits into separate pull requests so that the comments don't get intermingled and there easier to review / pull / etc.)

To me the Nginx part is ok. The quality of comments also improved, which is a great thing.

@vendruscolo thanks for the review!

(Cc: @AD7six)


I don't have much experience with Nginx so, the only thing I can add to the discussion is that: we'll stick to font/opentype for now.

@aitte
Copy link
Contributor Author

aitte commented Feb 25, 2013

@alrra: Thanks a lot for testing. Did you check "application/x-font-opentype"? Because your linked comment says that you tested "application/x-font-otf"? Just making sure.

Edit: I installed Chrome in a VM and can confirm the behavior: "Resource interpreted as Font but transferred with MIME type application/x-font-opentype: "http://10.0.1.2/Delicious-Roman.otf"". Hmm, Chrome IS doing the wrong thing here, font/* is not a valid mime type (http://www.iana.org/assignments/media-types), and Chrome understands application/x-font-ttf and application/font-woff; it's just application/x-font-opentype (and otf) that it barfs on, but I guess we should change this for Nginx too. One moment, I'll make a commit.

As for intermingled comments with multiple commits, you just have to click on "Commits" at the top of this page, then click on the commit. You can leave comments on a per-commit basis there. You can even click a particular line and comment on a line-level.

@alrra
Copy link
Member

alrra commented Feb 25, 2013

Did you check "application/x-font-opentype"? Because your linked comment says that you tested "application/x-font-otf"?

Yes. (tested for multiple MIME types and at first I accidentally uploaded the wrong screenshot, sorry about that)

As for intermingled comments, just click on "Commits" at the top of this page, then click on the commit. You can leave comments on a per-commit basis there. You can ever click a particular line and comment on a line-level.

Yes I know but, even with line / commit comments the discussion is still intermingled as, for a pull request about "Enhancements to the nginx configuration", we're discussing commits / lines in Apache (I hope you understand what I mean).

@aitte
Copy link
Contributor Author

aitte commented Feb 25, 2013

The opentype issue affected Nginx too in the old configs, and this discussion ended up leading to a fix in the Nginx configs (along with reverting the htaccess changes):
https://github.com/aitte/server-configs/commit/3ae37842133e41a2fc1cd0aeb2a87dd4b63fc0a8

Now all servers are brought in line with each other. I greped all the other configs to find ones that still use the incorrect values (or none at all) and will be pushing some more changes to fix those.

@aitte
Copy link
Contributor Author

aitte commented Feb 27, 2013

I have to leave planet Earth pretty shortly just so you know that I can't stick around here forever. ;-)

@aitte
Copy link
Contributor Author

aitte commented Feb 27, 2013

Okay I just finished re-reading all the changes, and basically, everything that's been brought up has been changed, and I even finalized the font mime type fixes for IIS, Nginx and Lighty, bringing every server in line with each other. Everything that's in here is in production use and has also been reviewed by several people now. If there's something you don't like, there's the "git cherry-pick" command to selectively merge all but a few of the patches, and I've given detailed motivations for the existence of every feature.

I seriously gotta leave Earth in 4 hours, so goodbye and have fun with the merge. :-)

Signing out.

location = /robots.txt { log_not_found off; }
location = /favicon.ico { log_not_found off; }
location = /apple-touch-icon.png { log_not_found off; }
location = /apple-touch-icon-precomposed.png { log_not_found off; }

This comment was marked as abuse.

@AD7six
Copy link
Member

AD7six commented Mar 3, 2013

@aitte Thanks for the commits - I'll begin cherry picking.

@h5bp:

  • do we want a block bad-guys feature in all server configs?
  • do we want to not-log common 404s?

AD7six pushed a commit that referenced this pull request Mar 24, 2013
AD7six pushed a commit that referenced this pull request Mar 26, 2013
@alrra
Copy link
Member

alrra commented Mar 30, 2013

do we want to not-log common 404s?

Personally, I don't think we should encourage that, it's important to know what generates 404 errors.

@AD7six
Copy link
Member

AD7six commented Apr 1, 2013

I've already cherry-picked all the commits I intend to take from this PR, of those not taken:

Not desired

Debatable

If these are desirable - they should be implemented for all servers (or at least, apache first)

@alrra
Copy link
Member

alrra commented Apr 1, 2013

Not related to nginx

  • aitte@1e79dde - apache/gae: change illegal font/opentype mime type to its proper type

Is this already accepted - Does this just need merging in?

No, it should not be merged see: h5bp/html5-boilerplate#1317 (apache, gae, iis, lighttpd, nginx, and node, are all ok from this point of view).

@AD7six
Copy link
Member

AD7six commented Apr 1, 2013

@alrra - cool, that leaves only the two proposed block features.

I don't think these blocks are robust/appropriate (e.g. PHP is identified as a generic baddie - but if you use PHP without modifying the user agent string you are more likely not a baddie and e.g. making an api request to a server). These blocks are more likely to introduce maintenance overhead (or simply be unused/forgotten) than to bring benefit to the repo as a whole.

As such that's everything that's to be taken from this PR.

@AD7six AD7six closed this Apr 1, 2013
alrra pushed a commit to h5bp/server-configs-nginx that referenced this pull request Jul 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants