Заметки по установке Nginx
Nginx — это бесплатный, открытый исходный код, высокопроизводительный HTTP-сервер и обратный прокси, а также сервер IMAP/POP3. В отличие от традиционных серверов, Nginx не использует потоки для обработки запросов. Вместо этого он использует гораздо более масштабируемую архитектуру на основе событий (асинхронную). Эта архитектура использует небольшие, но, что важнее, предсказуемые объёмы памяти под нагрузкой.
Для обработки PHP-файлов обычно используется PHP-FPM (FastCGI Process Manager). В настоящее время PHP-FPM входит в состав любого дистрибутива PHP для Unix. Phalcon + Nginx + PHP-FPM предоставляют мощный набор инструментов, обеспечивающих максимальную производительность ваших PHP-приложений.
Настройка Nginx для Phalcon
Ниже приведены потенциальные конфигурации, которые можно использовать для настройки nginx с Phalcon:
Базовая конфигурация
Использование $_GET[‘_url’] в качестве источника URI:
server {
listen 80;
server_name localhost.dev;
index index.php index.html index.htm;
set $root_path '/var/www/phalcon/public';
root $root_path;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
Использование $_SERVER[‘REQUEST_URI’] в качестве источника URI:
server {
listen 80;
server_name localhost.dev;
index index.php index.html index.htm;
set $root_path '/var/www/phalcon/public';
root $root_path;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
Выделенный экземпляр
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log /var/log/nginx/host.access.log main;
set $root_path '/srv/www/htdocs/phalcon-website/public';
location / {
root $root_path;
index index.php index.html index.htm;
# if file exists return it right away
if (-f $request_filename) {
break;
}
# otherwise rewrite it
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?_url=/$1 last;
break;
}
}
location ~ \.php {
# try_files $uri =404;
fastcgi_index /index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
}
Конфигурация по хосту
И эта вторая конфигурация позволяет вам иметь разные конфигурации по хостам:
server {
listen 80;
server_name localhost;
set $root_path '/var/www/$host/public';
root $root_path;
access_log /var/log/nginx/$host-access.log;
error_log /var/log/nginx/$host-error.log error;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
# try_files $uri =404;
fastcgi_index /index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/reference/nginx.html