How do I set nginx configuration settings on a per app basis in Dokku?
Asked Answered
C

1

10

I need to increase the client_max_body_size setting for a single app I have installed on a Dokku Paas. I could edit the nginx configuration globally, but that would be brittle, and I would like this setting to live with the app config where possible.

I have seen some plugins that help rewrite the nginx.conf file (eg. https://github.com/mikexstudios/dokku-nginx-alt), but that seems like overkill when I only want to change a single setting.

I have also noticed the nginx-configure plugin hook (https://github.com/progrium/dokku/pull/189), but I could not find clear instructions on how to use this from an app (where would I put the hook script, for example?).

What is the cleanest, most maintainable and most portable method of setting a single nginx configuration parameter on a per app basis?

Collective answered 27/8, 2014 at 14:27 Comment(5)
And what's the problem? This directive could be used anywhereHannover
Sorry - I don't follow. What directive? My question is how do I set a particular nginx setting on per app basis.Collective
nginx knows nothing about your app. Nginx works in terms on server and location blocks. Somewhere you have location block, that pass request to you app. You could add client_max_body_size directive to that block.Hannover
Did you see that this is specifically a question about dokku? I know how to configure this myself, but this is running in a PAAS environment where the nginx configuration is automatically generated. Thanks for your help though!Collective
I found this plugin which is using perl to modify the nginx.conf after deploying: github.com/fabiooshiro/dokku-client-max-body-size/blob/master/… You could conditionally modify the file per app (e.g. when a certain file in the app directory exists)Freehanded
E
21

This question is a bit old, but I ran into it while searching for a solution to the same question.

By default, dokku sites are installed in /home/dokku/{site-name}.

There is one main nginx file per app in this folder, nginx.conf. This file will be replaced every time you deploy so you don't want to change this.

However, you will see that this main nginx.conf file has the following line it in -

  include /home/dokku/{site-name}/nginx.conf.d/*.conf;

Which will include any .conf files in the nginx.conf.d folder.

So you can add a file called upload.conf (for example) to the nginx.conf.d folder, containing just client_max_body_size 50M;, and you'll achieve what you want to do.

After you create the directory and config file, ensure you chown them to the dokku user.

See https://github.com/dokku/dokku/blob/master/docs/configuration/nginx.md for further details.

Earplug answered 9/6, 2016 at 15:13 Comment(1)
i use react-router and i need to overwrite the "location / {}" and it seems i can't do that in nginx, any ideas?Mule

© 2022 - 2024 — McMap. All rights reserved.