Laravel Octane + nginx 子域:如何设置 nginx

问题描述 投票:0回答:1

我的 web.php 中有以下路线

$parsedUrl = parse_url($appUrl);
$host = $parsedUrl['host'];
Route::domain("{slug}.$host")->group(function () {
    Route::get('/', IndexController::class);
});

因此,当用户访问 client1.mywebsite.com 时,“client1”将作为 slug 传递给 IndexController。

一切正常,但我尝试使用辛烷,但我不知道如何设置我的 nginx 使其工作。

当我不需要获取子域名时,我通常这样做:

location /index.php {
    try_files /not_exists @octane;
}

location / {
    try_files $uri $uri/ @octane;
}

location @octane {
    set $suffix "";

    if ($uri = /index.php) {
        set $suffix ?$query_string;
    }

    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header Scheme $scheme;
    proxy_set_header SERVER_PORT $server_port;
    proxy_set_header REMOTE_ADDR $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    proxy_pass http://127.0.0.1:8000$suffix;
}

如何配置我的 nginx 接受动态子域并将其传递给 Octane?

laravel nginx nginx-reverse-proxy laravel-octane
1个回答
0
投票

我所做的工作是删除位置指令中的这个额外的“$uri/”:

来自

location / {
        try_files $uri $uri/ @octane;
    }

location / {
        try_files $uri  @octane;
    }

这样辛烷值就能与子域正常工作

这是完整的 nginx 配置

location /index.php {
    try_files /not_exists @octane;
}

location / {
    try_files $uri @octane;
}

location @octane {
    set $suffix "";

    if ($uri = /index.php) {
        set $suffix ?$query_string;
    }

    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header Scheme $scheme;
    proxy_set_header SERVER_PORT $server_port;
    proxy_set_header REMOTE_ADDR $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    proxy_pass http://127.0.0.1:8000$suffix;
}
© www.soinside.com 2019 - 2024. All rights reserved.