1

I am converting to nginx from apache. The application in question is as follows

/contentlibrary_js /contentlibrary_js/app/index.php --> one page ajax app /contentlibrary_js/pagecreator/index.php --> codeigniter application backend

I'm hoping to have one server block handle both the request to the frontend and the requests to the backend.

With the following configuration, I recieve "rewrite or internal redirection cycle while internally redirecting to "/index.php" in my nginx error log.

I tried adding a second location block to handle requests to the pagecreator/index.php file but I then the application hangs waiting for a response and I get "FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream," in the error log.

Any suggestions, Thanks

server {
    server_name contentlib.dev;
    #access_log logs/leonardo.access.log main;
    root /Users/acasanova/projects/mednet/contentlibrary_js;
    index  index.html index.htm index.php; 
    try_files $uri $uri/ /pagecreator/index.php /index.php /index.php$uri /index.php?$args;


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    # Codeigniter
    # location /pagecreator/{ 
    #     try_files $uri $uri/ index.php$request_uri;
    #    #root /Users/acasanova/projects/mednet/contentlibrary_js/pagecreator;
    #     fastcgi_pass   127.0.0.1:9000;
    #     fastcgi_index  index.php;
    #     fastcgi_param  SCRIPT_FILENAME  /Users/acasanova/projects/mednet/contentlibrary_js/pagecreator$fastcgi_script_name;

    #     include        fastcgi_params;           
    # }

    location ~ [^/]\.php(/|$)  { #GC
      # try_files $uri $uri/  /index.php$uri /index.php?$args;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       fastcgi_param  SCRIPT_FILENAME  $request_filename;
       include        fastcgi_params;
    }

    location ~ /\.ht {
        deny  all;
    }
}
user2108258
  • 303
  • 1
  • 3
  • 10
  • Your `try_files` block is quite odd. What is the thing you are trying to achieve with th eline? In practice it always goes to `pagecreator/index.php`, if there is no such file or directory as specified in the URI. – Tero Kilkanen Mar 28 '14 at 14:31
  • I'm trying to use one server block to handle requests to the front end and the backend. Should I split the blocks up? – user2108258 Mar 28 '14 at 19:49
  • Please try to describe your desired setup more concretely. Your one-liner in the message is very hard to understand. – Tero Kilkanen Mar 29 '14 at 12:54

1 Answers1

0

It seems I had a hard time understanding that the try_file directive will allow for other location blocks to be accessed. I kept thinking that once the request matches a location, then that is the only location block to be processed.

server {
    server_name contentlib.dev;
    access_log logs/contentlibrary_access.log;
    root /Users/acasanova/projects/mednet/contentlibrary_js;
    #default_type text/html;
    index  index.php index.html index.htm; 

    location /app{
        try_files $uri $uri/ /index.php /index.php$uri  =404;
        root /Users/acasanova/projects/mednet/contentlibrary_js/app;
    }

    location ~* \.(jpg|jpeg|gif|png|html|css|zip|tgz|gz|rar|doc|xls|pdf|ppt|tar|wav|bmp|rtf|swf|flv|txt|xml|docx|xlsx|js)$ {
        try_files $uri $uri/ /index.php$uri =404;
        access_log off;
    }

    location /pagecreator{       
        try_files $uri /index.php index.php$uri =404;     
        root /Users/acasanova/projects/mednet/contentlibrary_js/pagecreator;
    }

    location ~ [^/]\.php(/|$)  { #GC            
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   unix:/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;           
    }

    location ~ /\.ht {
        deny  all;
    }
}
user2108258
  • 303
  • 1
  • 3
  • 10