Vagrant用户似乎本身没有sudo / root权限

时间:2016-12-22 14:56:51

标签: nginx vagrant ubuntu-14.04 user-permissions

我试图确定Vagrant或nginx中是否存在错误。

我有以下Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise32"
  config.vm.network "private_network", ip: "10.0.1.7"
  config.vm.network :forwarded_port, guest: 8080, host: 9005
end

所以我运行vagrant up && vagrant ssh并且服务器提供并旋转。我想手动在我的新VM上安装nginx,所以(按the instructions在Ubuntu 14.04上安装nginx)然后运行:

sudo apt-get update
sudo apt-get install nginx

nginx安装。我运行mkdir ~/mysite然后将其/etc/nginx/nginx.conf文件更改为:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        location / {
            root   /home/vagrant/mysite;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include servers/*;
}

然后我运行nginx -s reload。我收到的错误是:

vagrant@precise32:~$ nginx -s reload
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2016/12/22 00:36:48 [notice] 1442#0: signal process started
2016/12/22 00:36:48 [alert] 1442#0: kill(890, 1) failed (1: Operation not permitted)

我的理解是vagrant应该是具有sudo访问权限和root权限的VM上的用户。没有?任何人都可以重现这一点并找出我无法使用自定义nginx.conf文件重新加载nginx的原因吗?

1 个答案:

答案 0 :(得分:1)

流浪者用户确实具有sudo特权,但不是因为他有权利以root身份运行命令。正如您使用sudo运行sudo apt-get update一样,您需要使用sudo运行nginx:

$ sudo nginx -s reload