Search code examples
environmentfreebsdrc

Where (i.e. which file) to set/assign systemwide environment variable which e.g., nginx can read like NODE_ENV on FreeBSD?


On FreeBSD, I need NODE_ENV=production and other systemwide environment variables to be set on startup, before nginx fires up.

Which is the right place i.e. file I do that?


Solution

  • One option could be to add your environment variables to /etc/login.conf in the setenv capability, for example:

    default:\
        :passwd_format=sha512:\
        :copyright=/etc/COPYRIGHT:\
        :welcome=/etc/motd:\
        :setenv=MAIL=/var/mail/$,BLOCKSIZE=K,NODE_ENV=production:\
        ...
    

    From the login.conf man:

    setenv          list           A comma-separated list of
                                   environment variables and
                                   values to which they are to
                                   be set.
    

    If you modity the /etc/login.conf file, don't forget to run:

    cap_mkdb /etc/login.conf