Is it reasonable to put a Phoenix application behind a Nginx proxy? I’m going to use some Nginx futures in the future, but wondering if Nginx won’t affect to much to speed and concurrency of Phoenix app.
nginx
works fantastically with Phoenix and I’ve seen no speed differences (except I have nginx host static files directly in some cases).
@OvermindDL1, thanks for the answer.
How about many concurent reuqests? Let’s say 50_000 websocket connections. Is Nginx fast enough for that?
@edit: Maybe cowboy
is a production ready server and Nginx is no longer necessary for SSL configuration and other security stuff?
I primarily use nginx as a front-end static-file cacher and proxy to the main server instance. On my 40k connection benchmark I saw no performance issue (honestly I could not tell nginx was there).
@OvermindDL1 - Just a quick question. How are you serving static assets via nginx? What is your release process? Do you use exrm? If so, what is the root directory for your nginx server?
I serve static assets just with a few location
directives in the nginx site file pointing to the various directories in the release that contain the /js/, /images/, /css/, and such directories.
I do use exrm right now, though I am highly looking forward at its replacement by the same author. It is hosted on Windows right now but transitioning to linux later. I do have a few smaller ones hosted myself via debian.
The ‘root’ path of the nginx site is directly routed to the erlang process, with a few location
hooks before that directive that catch some early things like /js/, /images/, etc… It is not really any different from hosting other things behind nginx.
@OvermindDL1 - Thanks. The reason I ask about how you setup the root path on nginx with exrm is because exrm has release versions on the path - example, the following could be your root path - ./lib/myApp-0.0.1/priv/static. When you deploy your next version, it will be ./lib/myApp-0.0.2/priv/static with a different version in the path.
I was wondering if you have script to manage the new deployments without touching ngnix config - example: symlink to the currently deployed - ./lib/current/priv/static and if you do that, how would you handle hot deploy’s? Is that shell scripted as well?
All of this is just so I know I am not missing out on something that is much easier to do with exrm itself.
I just symlink it to a predefined location, not really ideal and I am sure there is a better way, but I’m lazy and its a single command. ^.^
@satb root
value can contain variables, so you can set environment variable pointing at app location during deployment and access it using lua:
location /images/ {
set_by_lua $dynamic_root 'return os.getenv("MY_APP_ROOT")';
root $dynamic_root/assets;
}
However, you must restart the Nginx after each deployment.
A better solution is to copy static files to a fixed location (eg. /var/www/static). I’m using codeship and fabric to automate deployment tasks.
@pancake - Thank you. Both of them (lua scripts and codeship/fabric) are new that I didn’t know of before. I learn something new everyday thanks to folks like you that share.