问题
I have dozens of rewrite rules for legacy URLs from a previous incarnation of my application. I see three choices:
- Just add "match" lines in the routes file (config/routes.rb)
- Use rack-rewrite
- Create Nginx/Apache rewrite rules (Nginx in my case)
I imagine that 3 has better performance than 2, which has better performance than 1.
My questions:
- Is that true?
- If so, how much does it matter?
- Are there other trade-offs I might not have considered?
- Any other options altogether besides those three?
回答1:
- Yes, you have the performance order correct.
- Depends on your site, the traffic, the number of hits on those rewrite rules - in all likelihood the performance matters a lot less than the maintainability.
- Maintainability - use what you know, and what your developers know. Apache's rewrite syntax is easy to get wrong, and tends to be quite Write-Once-Read-Never. Nginx's is quite nice, but still a new DSL for you and your devs to learn. rack-rewrite is the inverse of Apache, it's actually hard to make a mistake because it's so simple (I think it's simpler than
routes.rb
) - None worth evaluating.
来源:https://stackoverflow.com/questions/5756965/routes-rb-vs-rack-rewrite-vs-nginx-apache-rewrite-rules