Laravel 在 Nginx 中非指定 public 目录的配置

在本地搭建了test/laravel,Nginx的虚拟主机我指定到test/文件夹下,结果 test.app/laravel/public/ 出来了,可是 test.app/laravel/public/home 的时候发现 file not found. 因为test/目录下有好多其他代码,不想每一个配置一个虚拟主机,刚开始搜索了好些代码,怎么配置就是不对,查询日志全是404:

2017/04/28 14:35:56 [error] 16935#0: *167 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: test.app, request: "GET /laravel/public/home HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.app"

或者 /laravel/public/home 目录不存在等等,各种搞各种调试就是那么的蛋疼。。。。。
刚开始看到http://www.cnblogs.com/lidabo/p/4169396.html 文章(咱看不懂官方的英文文档),就急吼吼的找下面的配置内容,没看上面的解说,最终还是蛋疼疼。。。。。
后来。。。。。实在憋得难受就从开头看。。。。中间迷糊睡着了。。。。,娘希匹,为什么非要在 ~ .php$ 前面过滤,原来是。。。。有点小白。。。。

普通location和正则location匹配顺序 的问题 反正不是一般理解的优先级处理。。。。。贴代码吧。。。。。

server {
  listen    80;
  server_name test.app;

  root  /Sites/test;
  index index.php index.html index.htm;

  location / {
      autoindex on;
      try_files $uri $uri/ /index.php?$args;
  }

  #proxy the php scripts to php-fpm
  location ~ \.php$ {
    #deny all;
    #return 406;

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;

    #fastcgi_split_path_info    ^(.+\.php)(/.+)$;

    #fastcgi_param  PATH_INFO       $fastcgi_path_info;
    #fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_intercept_errors on;

    include /usr/local/etc/nginx/fastcgi.conf;
  }

  location ~ /laravel/public/.+$ {
    try_files  $uri $uri/ /laravel/public/index.php?$args;
    #deny all;
    #return 405;
  }

  location ~ /\.ht {
    deny  all;
  }
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!