1
1
101-s2020-05-25 13:16:12
PHP
101-s, 2020-05-25 13:16:12

How to set up nginx and php-fpm?

Installed nginx and php-fpm, after setting the server response contains the body of the php script.
i.e. the server understands .php as a text file. Tell me, in which direction to dig?

nginx.conf
user nginx;
worker_processes 1; #колич ядер
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
  server_names_hash_bucket_size 64;
  
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
  client_max_body_size 300M; #макс разм ф для загр
  fastcgi_read_timeout 3000; #врем ожид выполн пхп скрипта

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
  
  gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

    include /etc/nginx/conf.d/*.conf;
}



site.conf
server {
listen 80;
    server_name site.ru;
    root /var/www/psy/www;
    index index.php;
    access_log /var/www/psy/logs/access.log main;
    error_log /var/www/psy/logs/error.log;

  location ~ \.php$ {
    # PHP-FPM	
    include fastcgi_params;
    try_files  $uri =404;
    fastcgi_pass   unix:/run/php-fpm/www.sock;

    fastcgi_index index.php;
    fastcgi_param DOCUMENT_ROOT /var/www/psy/www; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    
    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;
    }


}


www.conf
[www]

listen = /run/php-fpm/www.sock
listen.mode = 0660
listen.owner = nginx
listen.group = nginx
user = nginx
group = nginx

listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 6

slowlog = /var/www/psy/logs/slowlog.log

php_admin_flag[log_errors] = on
php_admin_value[error_log] = /var/www/psy/logs/www-error.log

php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanes, 2020-05-25
@Sanes

How to validly set permissions for nginx and php-fpm?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question