OS X 10.10 Localhost Environment using nginx, mysql, and php via Homebrew

Adam Vandover asked:

I am running Mac OSX 10.10 Yosemite with homebrew. I was using a localhost environment using MAMP and I wanted something that was less of a resource hog and without all the bloated extras. I have installed nginx, mysql and php56 with php-fpm and mcrypt via homebrew. I am using Laravel as my php framework. When I was using MAMP I would access Laravel projects like so:


Everything appears to be working ok when viewing the public folder landing page (the first uri above). Any other sub-locations (the second uri above) in my routes.php file return a 500 Internal Server error. After doing some searches, looking at tutorials and testing different nginx configurations this is what I currently have in my nginx.conf file:

worker_processes  4;
#pid        logs/nginx.pid;

events {
    worker_connections  1024;

http {
    include        mime.types;
    default_type   application/octet-stream;

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /Users/adam2k/www;
        index index.html index.htm index.php;   
        rewrite_log on;

        try_files $uri $uri/ @rewrite;

        location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;

        location / { 
           try_files $uri $uri/ /index.html;

        location ~ .php$ {
            try_files $uri = 404;
            include /usr/local/etc/nginx/fastcgi.conf;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            # break;

My /etc/hosts file looks like this:       localhost broadcasthost
::1             localhost

Under the error log I am receiving this message:

2015/02/10 12:51:32 [error] 22306#0: *19 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: ::1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost"

This makes me believe the issue lies within the

location / {...}

area in the config file, but I am not sure how to remedy this.

I’m not looking to do anything fancy with virtual hosts and adding special .dev or .local uris into my host file, but if that’s the only answer then I’m fine with putting in the extra configuration work.

My answer:

This is much too complicated, and parts of it appear to conflict with each other.

    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;

    location / { 
       try_files $uri $uri/ /index.html;

Simplify this to a single directive.

    try_files $uri $uri/ /index.php?_url=$request_uri;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.