N
N
Niko True2014-02-26 18:02:20
PHP
Niko True, 2014-02-26 18:02:20

How to configure nginx + php5-fpm?

I can not solve the issue of setting up this beast.
Ubuntu 12.04 x64, nginx-1.4.5.
Configs:
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;
                        }
}
}

host config
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;
        }
}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey, 2014-02-26
Protko @Fesor

well, you don't have a section proxying requests to php.
habrahabr.ru/post/113101 for example.

D
Dan Ivanov, 2014-02-27
@ptchol

Try
root /var/www/site;
at the server level.

D
Dan Ivanov, 2014-02-28
@ptchol

At the request of the comment, an example of a config.

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;
    }   

}

N
Niko True, 2014-02-28
@buloshnik

It's a matter of principle here, give a config with a connection via a unix socket.

M
maxyc webber, 2014-04-08
@MyNameIsSylor

the easiest way
1. delete /etc/nginx/*
2. insert nginx-boilerplate/src/* (look in Google for what it is)
3. install php5-fpm
restart all services
5. configure 3 lines in each virtualhost /etc/nginx /sites

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question