1. The *by_lua modules that tweak the nginx behaviour (for ex the rewrite_by_lua that is the lua equivalent of nginx http rewrite) module are always run after the standard nginx modules.
2. The choice of *by_lua module to use largely depends upon the problem that you are trying to solve. For example the init_by_lua module is used for initialization operations where as access_by_lua may be used to implement access policies for a location block. Personally among the various directives I find most use for content_by_lua.
Lua can access nginx at different phase, the most important directives are:
Rememeber to set lua_code_cache when developing
Use `ngx.location.capture` to issue a sub-request to other locations in nginx
`ngx.ctx` is a lua table to store data with a lifetime