使用 nginx 向 yii2 添加新文件夹

使用 nginx 向 yii2 添加新文件夹

我得到了 yii2 高级模板,但需要更改结构如下:

app 
 --backend
 --common
 --v1 
   --config
    --main.php
   --controller
    --SiteController.php
   --web
    --index.php

在 SiteController.php 中我创建了简单的动作:

public function actionTest()
    {
        return "tttt";
    }

并在 main.php 中的 urlManager 中添加此配置:

'urlManager' => [
            'enablePrettyUrl' => false,
            'rules' => [
                'GET v1/test' => 'site/test',
            ],
        ],

现在在 nginx.conf 中我有以下内容:

server {
    charset utf-8;
    client_max_body_size 512M;
    listen 80;
    listen 443 ssl http2 default_server;
    server_name app;

    set $base_root /app;
    root $base_root;

    ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
    
    error_log /var/log/nginx/error.log warn;
    access_log /var/log/nginx/access.log main;

    index index.php index.html index.htm;
    
    location /admin {
        root $base_root/backend/web;
        try_files $uri $uri/ /index.php$is_args$args;
       
       location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }
    }


    location /v1 {
        #rewrite ^/v1/(.*)$ /web/index.php/$uri break;
        root $base_root/v1/web;
        try_files $uri $uri/ /index.php$is_args$args;

          location = /v1 {
            # if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /v1/web/index.php$is_args$args;
        }
        
      #  autoindex on;
    }

    location ~ \.php$ {
        #rewrite ^/v1/(.*)$ /web/index.php/$uri break;

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

现在的问题是当我调用 API 时:

URL:http://localhost:8202/v1/test --> 不起作用并返回 No input file specified. 500

URL:http://localhost:8202/v1/web/index.php?r=site/test-->工作正常

我该怎么做才能调用短网址?

相关内容