A
A
Alexey Yarkov2016-07-30 00:49:38
PHP
Alexey Yarkov, 2016-07-30 00:49:38

Where to look for an error?

I'm trying to deploy my site from the hosting on the local. Found for Nginx config for Wordpress:

server {
    listen  80;
    server_name  domen.ru www.domen.ru; 
    root   /var/www/domen.ru/public_html;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~* ^.+.(js|css|png|jpg|jpeg|gif|ico)$ {
        access_log        off;
        expires           max;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

        fastcgi_param  DOCUMENT_ROOT    /domen.ru/public_html;
        fastcgi_param  SCRIPT_FILENAME  /domen.ru/public_html$fastcgi_script_name;
        fastcgi_param  PATH_TRANSLATED  /domen.ru/public_html$fastcgi_script_name;

        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
    
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    ## Disable viewing .htaccess & .htpassword 
    location ~ /\.ht {
        deny  all;
    }
}

The file was created, the validity was checked. Owner and rights changed:
chown -R www-data /var/www/domen.ru && chmod -R 750 /var/www/domen.ru

And in error.log I see this:
2016/07/30 00:41:06 [error] 22692#22692: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: domen.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "domen.ru"

And now the question is: what's not to like about php? What script does he need?
At the same time, such a config for tests works:
server {
  listen 80;
  listen [::]:80;

  root /var/www/php.local;

  # Add index.php to the list if you are using PHP
  index index.php index.html index.htm index.nginx-debian.html;

  server_name php.local www.php.local;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # With php7.0-cgi alone:
    #fastcgi_pass 127.0.0.1:9000;
    # With php7.0-fpm:
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  }

  location ~ /\.ht {
    deny all;
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lindon_cano, 2016-07-30
@Lindon_cano

You don't have php-fpm installed (or installed but listening to something else).

V
Vadim Misbakh-Soloviev, 2016-07-30
@mva

That's exactly why configs should not be thoughtlessly copied and pasted, but written by yourself. Then with experience comes an understanding of what is happening and how to fix it.
In general,
1) first remove all fastcgi_* directives that come after fastcgi_pass in wordpress server{}. Leave as you have in the "for tests" block.
2) chmod -R 750 /var/www/domen.ru<= never do that. If you really want to, then:

find /var/www/domen.ru -type d -print0 | xargs -0 chmod 750
find /var/www/domen.ru -type f -print0 | xargs -0 chmod 640

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question