我正在使用一个装有以下物品包装的Vagrant
盒子。Debian 8.5
tmux curl wget nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-intl php7.0-mysql php7.0-memcached memcached php-mbstring php-xml mariadb-server nodejs git unzip zip
我的问题是,当我尝试在任何目录中写入会话(例如登录后)时出现错误502 Bad Gateway
。
包含/var/log/nginx/error.log
以下内容
2016/07/18 21:31:59 [error] 15674#15674: *8 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.60.1, server
当我启用调试日志时这是输出。问题是,我并不认为这是一个权限问题,因为文件正在写入目录,甚至还有内容。但我仍然得到 502。
我的 vHost 配置
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/project/www/web;
index app_dev.php
# Important for Virtualbox
sendfile off;
# Make site accessible from http://www.project.dev/
server_name www.project.dev;
location / {
try_files $uri $uri/ /app_dev.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php/php7.0-fpm.sock
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_cache off;
fastcgi_index app_dev.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 1024k;
fastcgi_buffers 4 2048k;
fastcgi_busy_buffers_size 2048k;
}
}
我的 vagrant bootstrap 脚本
#!/usr/bin/env bash
projectname='project'
projectpath="/var/www/$projectname/www"
r_password=password
u_password=secret
echo "Initial update of the box"
apt-get update
cp ${projectpath}/vagrant_ressources/locale.gen /etc/
locale-gen de_DE.UTF-8
echo -e 'LANG=de_DE.UTF-8\nLC_ALL=de_DE.UTF-8' > /etc/default/locale
timedatectl set-timezone Europe/Berlin
mkdir -p ${projectpath}/static
echo "Adding Dotdeb repository"
cp ${projectpath}/vagrant_ressources/sources.list /etc/apt/
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
apt-get update
echo "Installing PHP 7.0 tools and extra software (tmux, curl, wget, nginx, fpm, cli, curl, gd, intl)"
apt-get install -y tmux curl wget nginx php7.0-fpm php7.0-cli php7.0-curl php7.0-gd php7.0-intl php7.0-mysql php7.0-memcached memcached
echo "Installing Laravel dependent stuff"
apt-get install -y php-mbstring php-xml
echo "Creating user and setting permissions"
adduser --disabled-login ${projectname}
adduser www-data ${projectname}
chown -Rf ${projectname}:${projectname} ${projectpath}
chmod 755 ${projectpath}/
chmod 750 ${projectpath}/web
chmod 750 ${projectpath}/static
echo "Initializing database"
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $r_password"
debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $r_password"
apt-get install -y mariadb-server
/etc/init.d/mysql restart
# allow remote access (required to access from our private network host. Note that this is completely insecure if used in any other way)
mysql -u root -p${r_password} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$r_password' WITH GRANT OPTION; FLUSH PRIVILEGES;"
mysql -u root -p${r_password} -e "CREATE DATABASE $projectname CHARACTER SET utf8;"
mysql -u root -p${r_password} -e "CREATE USER '$projectname'@'%' IDENTIFIED BY '$u_password';"
mysql -u root -p${r_password} -e "GRANT ALL PRIVILEGES ON $projectname.* TO '$projectname'@'%';"
echo "Setting up Nginx"
cp ${projectpath}/vagrant_ressources/${projectname} /etc/nginx/sites-available/${projectname}
ln -s /etc/nginx/sites-available/${projectname} /etc/nginx/sites-enabled/
rm -rf /etc/nginx/sites-available/default
echo "Setting up nodejs"
curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
apt-get install --yes nodejs
npm install -g gulp
echo "Setting up composer"
apt-get install -y git unzip zip
php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
echo "===================================================================================================="
echo "Installation finished. Run composer install in your working dir: $projectpath"
echo "===================================================================================================="
service nginx restart
如果你需要更多信息,我会提供给你。只要问就可以。
更新
我刚刚从 Debian 切换到 Ubuntu,问题仍然存在,所以这不是 Debian 的问题(而且由于我从 Symfony 切换到 Laravel,所以这也不是 Symfony/Laravel 的问题)。这意味着可能是Vagrant
,NFS
也许?或者Nginx
做错了什么
当使用 laravel 时这是日志。
[2016-07-23 19:03:56] local.ERROR: ErrorException: file_put_contents(): Exclusive locks are not supported for this stream in /var/www/project/www/vendor/laravel/framework/src/Illuminate/Filesy$
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/var/www/pingpo...', 109, Array)
#1 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(109): file_put_contents('/var/www/pingpo...', 'a:4:{s:6:"_toke...', 2)
#2 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/var/www/pingpo...', 'a:4:{s:6:"_toke...', true)
#3 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('4fd3fb4a7820527...', 'a:4:{s:6:"_toke...')
#4 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /var/www/project/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(I$
#6 /var/www/project/www/public/index.php(58): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#7 {main}
不知怎的,我认为这一定是 Vagrant 错误,因为当我尝试执行此操作时,sudo chown -R project:project /var/www/project/www
我收到了错误
chown: changing ownership of ‘{ANY FILE/FOLDER}’: Operation not permitted
答案1
这是一个老问题,所以我真的希望你现在已经解决了。
对于仍然面临此问题的任何人来说,我可以通过以下方式file_put_contents(): Exclusive locks are not supported for this stream
设置来解决问题:Vagrantfile
config.vm.synced_folder ".", "/vagrant",
:nfs => true,
:nfs_version => 4,
:nfs_udp => false,
:mount_options => ['sec=sys']
vagrant reload
更新后别忘了运行Vagrantfile
。