我在使用 Ubuntu 服务器 12.04 的 AWS EC2 机器上运行 Node/Express Web 服务器,并在 .bashrc 文件中设置了 4 个环境变量来访问我的数据库。如果我以普通用户身份运行服务器,它工作正常。但是,如果我以 sudo 身份运行 Node ,则环境变量未定义。
知道为什么它不起作用吗?
最佳答案
环境变量未传递给 sudo
:How to keep Environment Variables when Using SUDO
the trick is to add enviroment variables to sudoers config:
sudo visudo
add these lines
Defaults env_keep +="http_proxy" Defaults env_keep +="https_proxy"
form ArchLinux wiki https://wiki.archlinux.org/index.php/Sudo#Environment_variables_.28Outdated.3F.29
关于node.js - Ubuntu 上的 Node 服务器无法使用 sudo 访问环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22690644/