How can I do nginx rewrite?

Does nginx perform well as both app load balancer and static web server, or is it better to offload static files to other servers?

  • For example - a farm of nginx servers taking in all requests on port 80. Path that starts with /static will be served from nginx and all other requests go to tomcat server farm. Obviously putting /static behind a CDN would be ideal but current implementation of the app looks for /static as a relative URL. I am using the Opscode nginx cookbook to automatically add additional tomcat servers to the nginx config as they come online, but it doesn't seem to support ability to have different "app" servers. Will the static load have a major impact on nginx performance?

  • Answer:

    Yes, nginx can do both functions very effectively. I'm assuming you're even asking this question because you probably have a very large static content. if your static content is small enough (few MBs?) then nginx can beautifully do both functions on the same host. However, if your static content is large (in the order of giga bytes), then mixing both functions on the same physical host is not recommended due to the differing foot prints of both these use cases. The reasoning being - you have a finite resource called memory which is expensive and to be managed carefully. Both functions are memory intensive: File serving: memory will be used for the purpose of OS' fs cache + nginx's own cache. Mem usage is directly proportional to size of static content. proxying to app server: memory will be used for the purpose of network buffer. It really depends on your app server. Since you're mentioning 'tomcat', I will assume the JVM of tomcat will become the bottleneck and thus will put some memory strain on your nginx server. Mem usage is a function of your traffic and inversely proportional to your app server's ability to handle concurrent load. To measure the memory usage patterns for these two functions, it would be better to isolate the two operations - then, from the measurement, decide how much memory you need and based on that you can optimize / consolidate.

Suraj Kumar at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.