Nginx php 路由问题

Nginx php 路由问题

我是一名 Nginx 初学者,我发现了一个令人沮丧的情况。

我有一个 php 应用程序,在 localhost 上运行良好,但在将其移至 VPS 服务器后,路由中断 - 所有 URL 都呈现主页。我的 nginx 配置:

server {
    listen 80;
    server_name mysite.me;
    root /var/www/html;
    index index.php index.html index.htm;

    # Add additional types
    include mime.types;

    location /cockpit {
        try_files $uri  /cockpit/index.php?$args;
        index index.php index.html index.htm;
    }
        location / {
        try_files $uri /index.php$args;
        index index.php index.html index.htm;
    }

    location ~ \.php(/|\?|$) {
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#       fastcgi_split_path_info       ^(.+\.php)(.*)$;
#       fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param COCKPIT_URL_REWRITE On;
        include fastcgi_params;
    }
    location ~ .sqlite$ {
        deny all;
    }
    location /api {
        proxy_pass http://localhost:8889;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;.
        proxy_cache_bypass $http_upgrade;
    }

    location /banki {
        alias /var/www/banki;
        try_files $uri $uri/ /index.html last;
    }
}

我的 php 路由是

$app->get("/", function($params) use($app, $twig) {

    $collection  = cockpit('collections')->findOne('posts');
    $type_collection  = cockpit('collections')->find('Type');
    $template = $twig->load('index.twig');
    if ( $collection) {
        $posts = cockpit('collections')->find('posts');
    }
    return $template->render([
        'posts' => $posts,
        'types' => $type_collection,
    ]);
});

$app->bind("/:type", function($params) use($app, $twig) {

    $collection  = cockpit('collections')->findOne('posts');
    $type_collection  = cockpit('collections')->find('Type');
    $template = $twig->load('category.twig');
    if ( $collection) {
        $posts = cockpit('collections')->find('posts');
    }

    return $template->render([
        'type' => $params['type'],
        'posts' => $posts,
        'types' => $type_collection,
    ]);
});

我使用 Google 查看了很多想法,但没有一个对我有用。

我知道这不是应用程序本身的问题,因为如果我在端口 8080 运行 apache2 并转到 mysite.me:8080,应用程序就会按预期工作。

此外,/cockpit 位置工作正常。

有人可以帮忙吗?

相关内容