gpt4 book ai didi

nginx - 流浪的: config. vm.provision不允许我将文件复制到etc/nginx/conf.d吗?

转载 作者:行者123 更新时间:2023-12-01 06:55:20 24 4
gpt4 key购买 nike

我正在使用Nginx服务器。
我想使用Vagrantfile将配置文件复制到/etc/nginx/conf.d。
我使用的命令是:

config.vm.provision "file", source: "./bolt.local.conf", destination: "/etc/nginx/conf.d/bolt.local.conf"

我收到的错误是:
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.

我正在使用Bento/Ubuntu-16.04盒子。

我试图寻找一种方法来更改Provisioning命令的权限,但是我只找到了一种方法来更改config.vm.share_folder命令的所有者。

你知道答案吗?

最佳答案

如错误消息所示,也来自documentation:

The file uploads by the file provisioner are done as the SSH or PowerShell user. This is important since these users generally do not have elevated privileges on their own. If you want to upload files to locations that require elevated privileges, we recommend uploading them to temporary locations and then using the shell provisioner to move them into place.


因此, vagrant用户(如果未修改)用于scp文件,但是您不能使用它来访问 /etc/
要使其正常工作,您需要将其上传到一个临时位置,然后使用Shell Provisioner将其移动到目标目录:
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"
之所以起作用,是因为 shell provisioners默认情况下 privileged选项为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"

关于nginx - 流浪的: config. vm.provision不允许我将文件复制到etc/nginx/conf.d吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54067192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com