Yii2 - API位置的Nginx错误,但没有ADMIN位置

时间:2018-04-11 03:17:58

标签: php nginx yii2

我的开源Web应用程序出了问题,我尝试在我的Web应用程序中创建一个API应用程序,但是当我从浏览器访问它时,它从不调用“/api/web/index.php”文件。

它有效: “http://yii2-app-advanced.local/admin/site/login

它不起作用: “http://yii2-app-advanced.local/api/customer/login

我经常搜索,做了很多测试但没有成功。

这是我的nginx文件: https://github.com/prsolucoes/yii2-app-advanced/blob/module-api/extras/docker/nginx/conf.d/yii2-app-advanced.conf

这是存储库: https://github.com/prsolucoes/yii2-app-advanced/tree/module-api

我在nginx上添加了一些日志:

URI: /api/customer/login
BOOTSTRAP: index.php
TRY: /api/web/index.php
DOC ROOT: /usr/share/nginx/html/api/web
ROOT PATH: /usr/share/nginx/html

一切看起来都是正确的,因为管理员运行良好并且遵循相同的数据只将api更改为后端文件夹。

感谢。

1 个答案:

答案 0 :(得分:0)

server {
    charset      utf-8;
    client_max_body_size  200M;
    listen       80; ## listen for ipv4
    #listen       [::]:80 default_server ipv6only=on; ## listen for ipv6
    server_name  site.com;
    root         /var/www/site.com;


    location / {
        root  /var/www/site.com/frontend/web;
        try_files  $uri /frontend/web/index.php?$args;
        # avoiding processing of calls to non-existing static files by Yii
        location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
            access_log  off;
            expires  360d;
            try_files  $uri =404;
        }
    }

    location /api {
        root /var/www/site.com/api/web;
        try_files  $uri /api/web/index.php?$args;

        location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
          access_log  off;
          expires  360d;
          try_files  $uri =404;
        }
    }

    location /admin {
        alias  /var/www/site.com/backend/web;
        rewrite  ^(/admin)/$ $1 permanent;
        try_files  $uri /backend/web/index.php?$args;
    }

    location ^~ /uploads {
       autoindex on;
    }

    # avoiding processing of calls to non-existing static files by Yii

    location ~ ^/admin/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))$ {
        access_log  off;
        expires  360d;
        rewrite  ^/admin/(.+)$ /backend/web/$1 break;
        rewrite  ^/admin/(.+)/(.+)$ /backend/web/$1/$2 break;
        try_files  $uri =404;
    }

    location ~ \.php$ {
        include  fastcgi_params;
        # check your /etc/php5/fpm/pool.d/www.conf to see if PHP-FPM is listening on a socket or port
        fastcgi_pass  unix:/run/php/php7.2-fpm.sock; ## listen for socket
        #fastcgi_pass  127.0.0.1:9000; ## listen for port
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        try_files  $uri =404;
    }

    #error_page  404 /404.html;

    location = /requirements.php {
        deny all;
    }
    location ~ \.(ht|svn|git) {
        deny all;
    }
}