Magento 2 with Nginx and PHP7 – Cannot Access Admin

magento2nginxphp-7

We have installed a fresh Magento 2.0.2 with PHP 7.0.4 and Nginx.
The frontend works correctly, and we can create customer accounts.
But, the problem is we cannot access the admin. it gives an error: "The page you are looking for is temporarily unavailable. Please try again later."

enter image description here

And Debug logs show this line:

[2016-03-15 18:47:46] main.DEBUG: cache_invalidate:
{"method":"POST","url":"http:://example.com/index.php/admin/admin/index/index/key/a12f6c236de96a369096230294c30b32cfc3fe784788bfc44a3ec44009b0ed06/","invalidateInfo":{"tags":["BACKEND_MAINMENU"],"mode":"matchingAnyTag"},"is_exception":false}
[]

Nginx logs:

2016/03/15 19:11:12 [error] 6819#0: *5791 recv() failed (104:
Connection reset by peer) while reading response header from upstream,
client: 217.125.83.47, server: example.com, request: "POST
/index.php/admin/admin/index/index/key/9d1adcd6bb29c1491a34613a8b639c78618d0837ebcf36fbfdbabf2b7943b5a5/
HTTP/1.1", upstream: "fastcgi://127.0.0.1:9002", host:
"example.com", referrer:
"http:://example.com/index.php/admin/admin/index/index/key/9d1adcd6bb29c1491a34613a8b639c78618d0837ebcf36fbfdbabf2b7943b5a5/"

PD: http::// == http://

Our configuration files is:

NGINX:

server {

listen *:80;
root /var/www/example.com/web; #Use you mangeto2 location
index index.php index.html index.htm;
server_name example.com;

location /setup {
       try_files $uri $uri/ @setuphandler;}

# Rewrite Setup’s Internal Requests
   location @setuphandler {
       rewrite /setup /setup/index.php; }

# Rewrite Internal Requests
location / {  

        index index.php index.html;

#we have tested the 3 ways:
       try_files $uri $uri/ @handler;
#      try_files $uri $uri/ /index.php?_url=$uri&$args;
#      try_files $uri $uri/ /index.php?$args;
   }

    location @handler {

       rewrite / /index.php;
    }

     location /pub/static {

         try_files $uri $uri/ @static;

    }

     location @static {

          rewrite ^/pub/static/(.*)$ /pub/static.php?resource=$1? last;

    }

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;}

#pass the PHP scripts to f stcgi socket
location ~ \.php$ {
               try_files $uri =404;
               fastcgi_pass 127.0.0.1:9002;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
               fastcgi_read_timeout 900s;
#Magento 2 Developer Mode
#      fastcgi_param MAGE_MODE "developer";  
  } 
}

PHP7:

[web2]


listen = 127.0.0.1:9002
listen.owner = web2
listen.group = client1
listen.mode = 0660

user = web2
group = client1

pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 0

chdir = /

php_admin_value[open_basedir] = /var/www/clients/client1/web2/web:/var/www/clients/client1/web2/private:/var/www/clients/client1/web2/tmp:/var/www/example/web:/srv/www/example.com/web:/usr/local/php7/lib/php/extensions/:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin
php_admin_value[session.save_path] = /var/www/clients/client1/web2/tmp
php_admin_value[upload_tmp_dir] = /var/www/clients/client1/web2/tmp
php_admin_value[sendmail_path] = "/usr/sbin/sendmail -t -i -fwebmaster@example.com"

We have tried several configurations Nginx, and reinstall the Magento,

Please can someone help us.
Thank you,

Best Answer

We believe the problem was in the version of PHP 7.0.4. The Magento install wizard was showing we had php 7.1, but was not correct. May be that was the problems about admin login error. So we get a downgrade to 7.0.0 following this manual step by step: https://gist.github.com/tvlooy/881d0d67d0ad699c38a3

Then, we downloaded Magento 2.0.2 with sample data from official site. We have assigned the correct user to the folder (chown -R user:group *).

In case of Magento with sample data is important to increase memory_limit, for that go to /bin/magento and set

ini_set('memory_limit', '512M'); (or more memory if possible)

It is important to use the appropriate Nginx configuration file. The example of this post work for us.