nginx 重写或内部重定向,主要脚本未知

nginx 重写或内部重定向,主要脚本未知

我正在从 apache 转换为 nginx。相关应用程序如下

/contentlibrary_js /contentlibrary_js/app/index.php --> 单页 ajax 应用程序 /contentlibrary_js/pagecreator/index.php --> codeigniter 应用程序后端

我希望有一个服务器块可以同时处理前端的请求和后端的请求。

通过以下配置,我在 nginx 错误日志中收到“在内部重定向到“/index.php”时重写或内部重定向循环”。

我尝试添加第二个位置块来处理对 pagecreator/index.php 文件的请求,但随后应用程序挂起等待响应,并且在错误日志中收到“FastCGI 在 stderr 中发送:在从上游读取响应头时“主脚本未知””。

有任何建议吗?谢谢

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

答案1

我似乎很难理解 try_file 指令将允许访问其他位置块。我一直认为,一旦请求与某个位置匹配,那么这就是唯一要处理的位置块。

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

相关内容