Установка и настройка Nginx+PHP-FPM(FastCGI Process Manager) на Centos 6/7

Установка и настройка Nginx+PHPFPM(FastCGI Process Manager) на Centos 6/7

 

Имеем три виртуальных хоста с дом.каталогами в разных пользователях

joomla.us (/home/user/joomla/joomla.us)

wordpress.us (/home/user/wordpress/wordpress.us)

kamaok.us (/home/user/kamaok/kamaok.us)

Будет создано три php-fpm пула — по отдельному пулу для каждого пользователя, под которыми и будет работать php-fpm.

 

1.Установка Nginx

 

Centos 7

Либо

rpm —import http://nginx.org/keys/nginx_signing.key

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

 

Либо

rpm —import http://nginx.org/keys/nginx_signing.key

Создать файл-репозитария /etc/yum.repos.d/nginx.repo

nano /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=1

enabled=1

yum install nginx

 

Centos 6

Либо

rpm —import http://nginx.org/keys/nginx_signing.key

rpm –ihv http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

yum install nginx

 

Либо

rpm —import http://nginx.org/keys/nginx_signing.key

Создать файл-репозитария /etc/yum.repos.d/nginx.repo

nano /etc/yum.repos.d/nginx.repo

nano /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/6/$basearch/

gpgcheck=1

enabled=1

yum install nginx

 

2.Настройка Nginx

 

cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf~

[root@app01 ~]# grep -c processor /proc/cpuinfo

2

 

nano /etc/nginx/nginx.conf

user nginx;

worker_processes 2;

worker_rlimit_nofile 2048;

worker_priority -5;

error_log /var/log/nginx/error.log;

pid       /run/nginx.pid;

events {

worker_connections 1024;

use epoll;
multi_accept on;

}

http {

include       /etc/nginx/mime.types;

default_type application/octet-stream;

 

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;

access_log off;

 

#restricting on numbers of connection from one ip-adress
limit_conn_zone $binary_remote_addr zone=connections:10m;
limit_conn_log_level notice;
#limit_conn   connections  15;

#restricting numbers of connection per second from one ip-adress
limit_req_zone $binary_remote_addr zone=requests:10m rate=5r/s;
limit_req_log_level warn;

limit_req zone=requests burst=10;

 

sendfile       on;

tcp_nopush     on;

tcp_nodelay     on;

server_tokens   off;

keepalive_timeout 65;

types_hash_max_size 2048;

 

 

gzip on;

gzip_static     on;

gzip_comp_level 5;

gzip_min_length 1024;

gzip_proxied     any;

gzip_vary       on;

gzip_types     text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json font/ttf font/opentype application/vnd.ms-fontobject image/svg+xml;

gzip_disable   «msie6»;

 

index   index.php index.html index.htm;

 

open_file_cache   max=5000 inactive=20s;

open_file_cache_valid   30s;

open_file_cache_min_uses 2;

open_file_cache_errors   on;

 

fastcgi_buffer_size 128k;

fastcgi_buffers 4 256k;

fastcgi_busy_buffers_size 256k;

fastcgi_temp_file_write_size 256k;

 

fastcgi_connect_timeout 90;

fastcgi_send_timeout 90;

fastcgi_read_timeout 90;

 

client_max_body_size 100m;

client_body_buffer_size 8K;

 

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

}

 

nano /etc/nginx/conf.d/default.conf

server {

listen       80 default_server;

server_name localhost;

root         /usr/share/nginx/html;

 

location / {

try_files $uri $uri/ /index.php?$args;

index index.php index.html index.htm ;

}

 

location ~ \.php$ {

#root           /usr/share/nginx/html;

try_files $uri =404;

fastcgi_split_path_info ^(.+?\.php)(/.*)?$;

fastcgi_pass   unix:/var/run/php5-fpm-joomla.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include       fastcgi_params;

}

 

location ~ /\.ht {

deny all;

}

 

error_page   500 502 503 504 /50x.html;

location = /50x.html {

}

 

location /nginx_status {

stub_status on;

access_log   off;

allow 127.0.0.1;

allow 192.168.1.0/24;

deny all;

}

 

location ~ ^/(status-joomla|ping-joomla)$ {

fastcgi_pass   unix:/var/run/php5-fpm-joomla.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

access_log off;

allow 127.0.0.1;

allow 192.168.1.0/24;

deny all;

}

 

location ~ ^/(status-wordpress|ping-wordpress)$ {

fastcgi_pass   unix:/var/run/php5-fpm-wordpress.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

access_log   off;

allow 127.0.0.1;

allow 192.168.1.0/24;

deny all;

}

 

location ~ ^/(status-kamaok|ping-kamaok)$ {

fastcgi_pass   unix:/var/run/php5-fpm-kamaok.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

access_log   off;

allow 127.0.0.1;

allow 192.168.1.0/24;

deny all;

}

}

 

nano /etc/nginx/conf.d/joomla.conf

 

server {

listen       80;

server_name joomla.us *.joomla.us;

root         /home/user/joomla/joomla.us;

 

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

 

location / {

try_files $uri $uri/ /index.php?$args;

}

 

location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {

access_log off;

expires max;

}

 

location ~ \.php$ {

try_files $uri =404;

fastcgi_split_path_info ^(.+?\.php)(/.*)?$;

fastcgi_pass   unix:/var/run/php5-fpm-joomla.sock;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include       fastcgi_params;

}

 

location ~ /\.ht {

deny all;

}

 

error_page   500 502 503 504 /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;

}

 

 

cp /etc/nginx/conf.d/joomla.conf /etc/nginx/conf.d/wordpress.conf

cp /etc/nginx/conf.d/joomla.conf /etc/nginx/conf.d/kamaok.conf

sed -i ‘s/joomla/wordpress/g’ /etc/nginx/conf.d/wordpress.conf

sed -i ‘s/joomla/kamaok/g’ /etc/nginx/conf.d/kamaok.conf

 

[root@app01 nginx]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

 

3.Запуск Nginx и добавление в автозагрузку

Centos 7

systemctl start nginx

systemctl enable nginx

 

Centos6

service nginx start (/etc/init.d/nginx start)

chkconfig —level 2345 nginx on

 

4.Установка PHP-FPM

yum install php php-fpm php-mysql

 

5.Настройка PHP-FPM

cp /etc/php-fpm.conf /etc/php-fpm.conf~

 

cat /etc/php-fpm.conf | grep -v «\#\|\;\|^$»

include=/etc/php-fpm.d/*.conf

[global]

pid = /run/php-fpm/php-fpm.pid

error_log = /var/log/php-fpm/error.log

emergency_restart_threshold = 10

emergency_restart_interval = 1m

process_control_timeout = 10s

daemonize = yes

 

mv /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf~

 

nano /etc/php-fpm.d/joomla.conf

[root@app01 ~]# cat /etc/php-fpm.d/joomla.conf | grep -v «\;» | grep -v ^$

[joomla]

listen = /var/run/php5-fpm-joomla.sock

listen.owner = joomla

listen.group = joomla

listen.mode = 0666

user = joomla

group = joomla

pm = dynamic

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

pm.status_path = /status-joomla

ping.path = /ping-joomla

ping.response = pong-joomla

request_slowlog_timeout = 3s

slowlog = /var/log/php-fpm/joomla-slow.log

catch_workers_output = yes

php_admin_value[error_log] = /var/log/php-fpm/joomla-error.log

php_admin_flag[log_errors] = on

php_admin_value[memory_limit] = 128M

php_value[session.save_handler] = files

php_value[session.save_path] = /var/lib/php/session-joomla

 

mkdir /var/lib/php/session-joomla

chown -R joomla:joomla /var/lib/php/session-joomla

 

nano /etc/php.ini

expose_php = Off

max_execution_time = 300

max_input_time = 600

memory_limit = 256M

post_max_size = 100M

cgi.fix_pathinfo=0

upload_max_filesize = 100M

date.timezone = Europe/Kiev

 

 

cp /etc/php-fpm.d/joomla.conf /etc/php-fpm.d/wordpress.conf

cp /etc/php-fpm.d/joomla.conf /etc/php-fpm.d/kamaok.conf

mkdir /var/lib/php/session-wordpress

mkdir /var/lib/php/session-kamaok

chown -R wordpress:wordpress /var/lib/php/session-wordpress

chown -R kamaok:kamaok /var/lib/php/session-kamaok

 

[root@app01 nginx]# php-fpm -t

[06-Jan-2015 19:51:35] NOTICE: configuration file /etc/php-fpm.conf test is successful

 

6.Запуск PHPFPM и добавление в автозагрузку

Centos 7

systemctl start php-fpm

systemctl enable php-fpm

 

Centos6

service php-fpm start (/etc/init.d/php-fpm start)

chkconfig —level 2345 php-fpm on

 

[root@app01 nginx]# ls -al /var/run/ | grep php

srw-rw-rw-   1 joomla   joomla       0 Jan 6 19:51 php5-fpm-joomla.sock

srw-rw-rw-   1 kamaok   kamaok       0 Jan 6 19:51 php5-fpm-kamaok.sock

srw-rw-rw-   1 wordpress wordpress   0 Jan 6 19:51 php5-fpm-wordpress.sock

drwxr-xr-x   2 root     root       60 Jan 6 19:51 php-fpm

 

Комментирование и размещение ссылок запрещено.

Комментарии закрыты.

Яндекс.Метрика