buloshnik
@buloshnik
мужик

Как провести настройку nginx + php5-fpm?

Не могу никак решить вопрос настройки данного зверя.
Ubuntu 12.04 x64, nginx-1.4.5.
Конфиги:
nginx.conf
user www-data;
worker_processes 2;
pid /run/nginx.pid;

events {
        worker_connections 1024;
}

http {
        sendfile on;
        keepalive_timeout 5 5;
        types_hash_max_size 2048;
        server_tokens off;

        limit_conn_zone $binary_remote_addr zone=one:3m;

        #include /etc/nginx/mime.types;
        #default_type application/octet-stream;

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

        gzip on;
        gzip_disable "msie6";

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

server {
        if ($request_method !~ ^(GET|HEAD|POST)$ ) {
                return 444;
        }

        if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
                return 403;
        }

        if ($http_user_agent ~* msnbot|scrapbot) {
                return 403;
        }

        if ( $http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen) ) {
                return 403;
        }

        limit_conn one 10;
 location ~ \.php$
                        {
                                fastcgi_pass unix:/var/run/php-fpm.sock;
                                fastcgi_index index.php;
                                fastcgi_param       SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                                fastcgi_ignore_client_abort off;
                                include fastcgi_params;
                                try_files       $uri $uri/ $uri/index.php?q=$uri&$args $uri/index.php   =405;
                        }
}
}

конфиг хоста
server {
        listen 80;
        server_name site.ru;
        location / {
                rewrite ^/(.*)$ https://$host/$1 permanent;
        }
}

server {
        listen 443 ssl;
        server_name site.ru;

        client_body_buffer_size 1K;
        client_header_buffer_size 1k;
        client_max_body_size 1k;
        large_client_header_buffers 2 1k;
        client_body_timeout 10;
        client_header_timeout 10;
        keepalive_timeout 5 5;
        send_timeout 10;

        if ($host !~ ^(site.ru|www.site.ru)$ ) {
                return 444;
        }

        location / {
                index index.php index.html index.htm;
                gzip_static on;
                root /var/www/site;
        }

        location /images/ {
                valid_referers none blocked www.site.ru site.ru;
                if ($invalid_referer) {
                        return 403;
                }
        }

        error_page 404 /404.html;

        location = /404.html {
                root /var/nginx/html;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {   
                root /var/nginx/html;
        }
}
  • Вопрос задан
  • 3470 просмотров
Пригласить эксперта
Ответы на вопрос 5
Fesor
@Fesor
Full-stack developer (Symfony, Angular)
ну у вас отсутствует секция, проксирующая запросы к php.
habrahabr.ru/post/113101 например.
Ответ написан
ptchol
@ptchol
Linux system administrator
Попробуйте прописать
root /var/www/site;
на уровне сервера.
Ответ написан
ptchol
@ptchol
Linux system administrator
По просьбе из коммента, пример конфига.
server {
    listen      80;
    server_name domain.ru;

    root /var/www/domain.ru;

    access_log  /data/logs/nginx/domain.ru.access.log main;
    error_log   /data/logs/nginx/domain.ru.error.log;

    location / {
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov|xml|flv|f4v)$ {
        add_header Cache-Control public;
        expires 24h;
    }

    location ~ \.php$ {
        fastcgi_pass                unix:/var/run/php-fpm.sock;
        fastcgi_index               index.php;
        fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include                     fastcgi_params;
    }   

}
Ответ написан
buloshnik
@buloshnik Автор вопроса
мужик
Тут уже дело принципа, дайте конфиг с подключением через unix socket.
Ответ написан
@MyNameIsSylor
самый простой способ
1. удаляете /etc/nginx/*
2. вставляете nginx-boilerplate/src/* (в гугле поищите что это)
3. устанавливаете php5-fpm

перезапускаете ввсе сервисы

5. настраиваете 3 строчки в каждом виртуалхосте /etc/nginx/sites
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы