502 Bad Gateway ao tentar gravar uma sessão com PHP e nginx em uma caixa vagabunda debian

1

Estou usando uma Vagrant box com Debian 8.5 com os seguintes pacotes de material.

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

Meu problema é que, quando tento escrever uma sessão (por exemplo, após um login) em qualquer diretório, estou recebendo um erro 502 Bad Gateway .

O /var/log/nginx/error.log tem o seguinte conteúdo

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

Quando eu habilito o log de depuração esta é a saída . O problema é que eu não acho que seja um problema de permissão, pois os arquivos estão sendo gravados no diretório e existem até conteúdos. Mas eu ainda recebo o 502.

Meu vHost conf

##
# 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;
    }
}

Meus scripts de bootstrap vagantes

#!/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

Se precisar de mais alguma informação, eu lhe darei. Basta perguntar.

ATUALIZAÇÕES
Eu apenas mudei do Debian para o Ubuntu e o problema ainda existe, então não é um problema do Debian (e desde que eu mudei do Symfony para o Laravel, também não é um problema do Symfony / Laravel). Isso significa que pode ser Vagrant , NFS talvez? ou Nginx fazendo algo que não está certo

Quando usar laravel, esse é o log.

[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}

De alguma forma eu acho que isso deve ser um erro do Vagrant, já que ao tentar fazer sudo chown -R project:project /var/www/project/www estou recebendo o erro

chown: changing ownership of ‘{ANY FILE/FOLDER}’: Operation not permitted

    
por Musterknabe 18.07.2016 / 21:54

1 resposta

1

Pergunta antiga, então eu realmente espero que você tenha resolvido isso agora.

Para qualquer outra pessoa que ainda esteja enfrentando isso, consegui corrigir o problema de file_put_contents(): Exclusive locks are not supported for this stream configurando meu Vagrantfile dessa maneira:

config.vm.synced_folder ".", "/vagrant", 
    :nfs => true, 
    :nfs_version => 4, 
    :nfs_udp => false, 
    :mount_options => ['sec=sys']

Não se esqueça de executar vagrant reload depois de atualizar Vagrantfile .

    
por 26.02.2018 / 16:51