使用nginx设置Vagrant文件夹权限

5
我是一个新手,正在使用 vagrant,并且遇到了无法正常工作的问题。它已经通过端口转发运行良好,我可以访问它。但是,我在让 bower 和 gulp 正常工作方面遇到了麻烦。
问题似乎源于 /var/www 目录被 www-data/www-data 拥有的原因。即使将 vagrant 添加到 www-data 组后,vagrant 用户仍没有任何目录的写入权限。我甚至不能使用 sudo chmod 来添加文件的写权限。
每次尝试运行 bower、gulp 或者 git,我都会收到拒绝访问的错误提示。
非常感谢任何帮助。
Vagrant 文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise32"

  config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true

  config.ssh.private_key_path = ['~/.vagrant.d/insecure_private_key', '~/.ssh/id_rsa.pub']
  config.ssh.forward_agent = true

  config.vm.synced_folder "/home/develop/b3c-dev", "/var/www", create: true, group: "vagrant", owner: "www-data"
  config.vm.synced_folder "/home/vagrant/b3c_ee/provision", "/var/provision", create: true, group: "root", owner: "root"

  config.vm.provider "virtualbox" do |v|
    v.name = "B3C Expression Engine Dev Vagrant"
    v.customize ["modifyvm", :id, "--memory", "1024"]
  end

  config.vm.provision "shell", path: "provision/setup.sh"
end

Nginx配置:

server {
    listen 80;
    server_name test.dev www.test.dev;

    root /var/www/public/;
    index index.php index.html;

    access_log /var/log/nginx/b3c-dev-access.log;
    error_log  /var/log/nginx/b3c-dev-error.log info;
    # Important for VirtualBox
    # sendfile off;

    location / {
        index index.php;
        try_files $uri $uri/ @ee;
      }

      location @ee {
        rewrite ^(.*) /index.php?$1 last;
      }

    location ~* \.php {
        include fastcgi_params;

        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_cache off;
        fastcgi_index index.php;
    }
}
1个回答

7
我会将共享文件夹以vagrant为所有者和组的身份进行加载,然后在/etc/php5/fpm/pool.d/www.conf中更改用户和组为vagrant。
要在php-fpm的配置文件中更改用户和组,请在provision/setup.sh的末尾添加以下两行代码:
sed -i 's/user = www-data/user = vagrant/g' /etc/php5/fpm/pool.d/www.conf
sed -i 's/group = www-data/group = vagrant/g' /etc/php5/fpm/pool.d/www.conf

如果这没有帮助,请尝试递归增加/var/www的权限。

2021年的文件路径为/etc/php/8.0/fpm/pool.d/www.conf - cgaldiolo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接