vlucas / bulletphp

A resource-oriented micro PHP framework
http://bulletphp.com
BSD 3-Clause "New" or "Revised" License
416 stars 50 forks source link

Nginx example #44

Closed a1ee9b closed 7 years ago

a1ee9b commented 10 years ago

I just wanted to provide an example for nginx. The following seems to do the trick, although I haven't tested all constellations yet.

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

The full configuration looks like this:

upstream php {
    server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name mysite.local;

    access_log /var/log/nginx/mysite.log;
    error_log /var/log/nginx/mysite-error.log;

    root /data;
    index index.php;

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

    #caching of static files
    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt|ico|pdf|flv)$ {
        access_log off;
        log_not_found off;
        expires max;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac)
    location ~ /\. {
        deny all;
    }

    location ~ .php$ {
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        include fastcgi_params;
    }
}

Please let me know if you find this useful or found improvements.