rogerpence
9/25/2015 - 5:18 AM

Minimal nginx config for PHP

Minimal nginx config for PHP

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        ##fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location / {
        location ~* ^(.+)-(?:\d+)\.?(?:\d+)?\.?(?:\d+)?\.(js|css|png|jpe?g|gif|pdf|rtf|txt|docx?|gz|g?zip|ppt|mp4|ogv|flv|webm|mov)$ {
            try_files $uri $1.$2 /index.php$is_args$args;
        }

        location / {
            try_files $uri /index.php$is_args$args;
        }
    }

    location ~ ^/(index|dev)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;

        include fastcgi.conf;
    }
}