Hen*_*k D 6 nginx vagrantfile ubuntu-16.04
我正在使用 Nginx 服务器。我想使用 Vagrantfile 将配置文件复制到 /etc/nginx/conf.d。我使用的命令是:
config.vm.provision "file", source: "./bolt.local.conf", destination: "/etc/nginx/conf.d/bolt.local.conf"
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
Failed to upload a file to the guest VM via SCP due to a permissions
error. This is normally because the SSH user doesn't have permission
to write to the destination location. Alternately, the user running
Vagrant on the host machine may not have permission to read the file.
Run Code Online (Sandbox Code Playgroud)
我正在使用便当/ubuntu-16.04 盒子。
我试图寻找一种方法来更改供应命令的权限,但我只找到了更改 config.vm.share_folder 命令的所有者的方法。
你知道答案吗?
lee*_*ong 14
正如错误消息所暗示的那样,也来自文档:
文件供应商的文件上传是作为 SSH 或 PowerShell 用户完成的。这很重要,因为这些用户通常自己没有提升的权限。如果要将文件上传到需要提升权限的位置,我们建议将它们上传到临时位置,然后使用 shell 配置程序将它们移动到位。
因此,vagrant用户(如果未修改)用于 scp 文件,但您无法/etc/使用它进行访问。
要使其工作,您需要将其上传到一个临时位置,然后使用 shell 配置器将其移动到目标目录:
config.vm.provision "file",
source: "./bolt.local.conf",
destination: "/tmp/bolt.local.conf"
config.vm.provision "shell",
inline: "mv /tmp/bolt.local.conf /etc/nginx/conf.d/bolt.local.conf"
Run Code Online (Sandbox Code Playgroud)
之所以可行,是因为该privileged选项在shell 配置器上默认为 true 。但是有两个配置器只是为了复制一个配置文件有点令人费解,对吧?
好吧,如果该文件已经在您的共享文件夹中,您可以使用 shell 配置器将其复制到 nginx 目录中,这样您最终会得到如下内容:
# This is the default and serve just as a reminder
config.vm.synced_folder ".", "/vagrant"
config.vm.provision "shell",
inline: "cp /vagrant/bolt.local.conf /etc/nginx/conf.d/bolt.local.conf"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4413 次 |
| 最近记录: |