网址下的Nginx前端和后端

时间:2016-10-26 03:43:47

标签: nginx

我有这个nginx配置:

> (Add-Type -PassThru 'namespace net.same2u { public class SomeType {} }')::New()
net.same2u.SomeType  # the full type name

其中:

  • A:前端(棱角分明)
  • B:后端(流明)

后来我想添加

  • C:管理员(有角度的)
  • D:支持(角度)

但是即使对于这种配置,当我尝试访问 hans.site.dev/api / 时,它会给我这个错误: " /无功/网络/的 /public/index.php"失败(2:没有这样的文件或目录),客户端:192.168.56.1,服务器:hans.site.dev,请求:" GET / api / HTTP / 1.1",主机:" hans .site.dev"

为什么它引用 a 而不是 b ?以及如何解决它?

1 个答案:

答案 0 :(得分:1)

您的try_files声明不正确。

  • location /api块中,$uri变量已包含/api前缀。

  • 默认操作目前将客户端发送到其他index.php而非所需位置/api/index.php

试试这个:

location /api {
    root /var/www/b/public;
    index  index.php index.html index.htm;
    try_files $uri $uri/ /api/index.php?$query_string;

使用此配置,所有文件都位于目录结构中:

/var/www/b/public/api/

请注意/api是最终目录组件。

编辑:如果您必须使用alias指令,请注意try_files关于try_files的使用情况。因此,您的if函数需要使用if语句重新实现。关于root指令的使用,请注意open issue

alias替换为try_filesif替换为离散的if语句。 rewrite ... last块的内容有限,因此我们仅使用index语句。

使用多个if语句实现SCRIPT_FILENAME指令(它们都是非常必要的)。可能有更好的方法。

$request_filename设置为location /api { alias /var/www/b/public; if (-f $request_filename/index.php) { rewrite ^ $uri/index.php last; } if (-f $request_filename/index.html) { rewrite ^ $uri/index.html last; } if (-f $request_filename/index.htm) { rewrite ^ $uri/index.htm last; } if (!-f $request_filename) { rewrite ^ /api/index.php last; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $request_filename; } } ,这是别名路径名。

classificationGroup = group;
      aq.id(R.id.tv_group).text(LogGroup.GROUP_NAMES[group]);
      aq.id(R.id.tv_total).text("" + usage + " calls");

      Intent intent = new Intent(getActivity(), CallLogsFragment.class);
      Bundle b = new Bundle();
      b.putInt("key",classificationGroup); 
      intent.putExtras(b); 
      startActivity(intent);