1.Установка и настройка Nginx
cd /usr/ports/www/nginx
make install clean
cd /usr/local/etc/nginx/
cp nginx.conf nginx.conf~
nano nginx.conf (см.ниже)
nginx –t
mkdir -p /var/tmp/nginx/client_body_temp
mkdir -p /var/log/nginx
nano conf.d/joomla.to.conf (см.ниже)
nano conf.d/wordpress.to.conf (см.ниже)
htpasswd -c .htpasswd tom
htpasswd .htpasswd bob
Создаем символьную ссылку phpmyadmin для phpMyAdmin’а
ln -s /usr/local/www/phpMyAdmin /usr/local/www/apache22/data/phpmyadmin
/usr/local/www/apache22/data/ — это DocumentRoot для сервера по умолчанию
nginx –t
nano /etc/rc.conf
nginx_enable=»YES»
/usr/local/etc/rc.d/nginx start
2.Установка и настройка PHP—FPM
Начиная с версии php-5.3.3 php-fpm идет в составе php ,как опция при сборке из портов php
Мои опции сборки PHP
cat /var/db/ports/lang_php5/options | grep -v UNSET
_OPTIONS_READ=php5-5.4.17
OPTIONS_FILE_SET+=CLI
OPTIONS_FILE_SET+=CGI
OPTIONS_FILE_SET+=FPM
OPTIONS_FILE_SET+=APACHE
OPTIONS_FILE_SET+=LINKTHR
для версий младше 5.3.3. инструкцию смотрим на сайте
cp /usr/local/etc/php-fpm.conf /usr/local/etc/php-fpm.conf~
nano /usr/local/etc/php-fpm.conf
Создаем необходимые файлы
/var/log/{php-fpm.log,php-fpm.slow.log,php-fpm.www.log}
Проверка синтаксиса
php-fpm -t
nano /etc/rc.conf
php_fpm_enable=»YES»
/usr/local/etc/rc.d/php-fpm start
cat /usr/local/etc/nginx/nginx.conf
user www www;
worker_processes 1;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use kqueue;
}
http {
include 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;
client_header_timeout 10;
client_body_timeout 10;
send_timeout 10;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_static on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_disable msie6;
gzip_types text/plain application/json text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml;
keepalive_timeout 5 5;
limit_conn_zone $binary_remote_addr zone=addr:10m;
output_buffers 1 32k;
client_body_buffer_size 8K;
postpone_output 1460;
index index.html;
client_max_body_size 80m;
index index.html index.htm index.php;
include /usr/local/etc/nginx/conf.d/*.conf;
server {
listen 192.168.1.42:80 default_server;
server_name _;
#charset koi8-r;
location / {
root /usr/local/www/apache22/data;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-fpm.sock; #Если nginx и php-fpm запущены на одном и том # же сервере,тогда подключаемся через сокет вместо использования портов
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Здесь у меня почему-то не завелось через переменную $document_root, пришлось #принудительно указывать полный путь
fastcgi_param SCRIPT_FILENAME /usr/local/www/apache22/data$fastcgi_script_name;
include fastcgi_params;
}
# phpMyAdmin
location ~ ^/phpmyadmin/(.*\.php)$ {
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/phpMyAdmin/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/phpMyAdmin;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
location ~ /\.ht {
deny all;
}
location /server-status {
stub_status on;
access_log on;
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
}
}
}
cat /usr/local/etc/nginx/conf.d/joomla.to.conf
server {
listen 192.168.1.42:80;
server_name joomla.to www.joomla.to;
location /server-status {
stub_status on;
access_log on;
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
}
location / {
root /usr/local/www/joomla.to;
try_files $uri $uri/ /index.php;
satisfy any;
allow 192.168.1.0/24;
allow 127.0.0.1/32;
deny all;
auth_basic «Restricted»;
auth_basic_user_file /usr/local/etc/nginx/.htpasswd;
}
location ~ \.php$ {
root /usr/local/www/joomla.to;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
cat /usr/local/etc/nginx/conf.d/wordpress.to.conf
server {
listen 80;
server_name wordpress.to www.wordpress.to;
location /server-status {
stub_status on;
access_log on;
allow 127.0.0.1;
allow 192.168.1.0/24;
deny all;
}
location / {
root /usr/local/www/wordpress.to;
try_files $uri $uri/ /index.php;
satisfy any;
allow 192.168.1.0/24;
allow 127.0.0.1/32;
deny all;
auth_basic «Restricted»;
auth_basic_user_file /usr/local/etc/nginx/.htpasswd;
}
location ~ \.php$ {
root /usr/local/www/wordpress.to;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
cat /usr/local/etc/php-fpm.conf | grep -v \;
[global]
pid = run/php-fpm.pid
error_log = /var/log/php-fpm.log
log_level = notice
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5
daemonize = yes
events.mechanism = kqueue
[www]
user = www
group = www
listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm.slow.log
request_slowlog_timeout = 10
rlimit_files = 1024
rlimit_core = 0
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php-fpm.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 32M
Источники:
- http://jhukov.blogspot.com/2011/01/php5-fpm-nginx-freebsd.html
- http://blog.magwai.ru/831/
- http://wiki.firstvds.ru/index.php/%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_freebsd%2Bnginx%2Bphp-fpm%2BMySQL%2BphpMyAdmin#.D0.A1.D1.82.D0.B0.D0.B2.D0.B8.D0.BC_nginx
- http://habrahabr.ru/post/67152/
- http://wiki.firstvds.ru/index.php/%D0%92%D1%8B%D1%81%D0%BE%D0%BA%D0%BE%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%BE%D0%B4%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_web-%D1%81%D0%B5%D1%80%D0%B2%D0%B5%D1%80
- http://nginx.org/ru/docs
- http://wiki.nginx.org/Pitfalls
- http://rtfm.co.ua/freebsd-ustanovka-i-nastrojka-nginx-php-fpm/