mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51:37 +00:00
reverse proxy sites
This commit is contained in:
parent
ff4d560e44
commit
8a8467233e
@ -13,6 +13,7 @@
|
|||||||
use App\Notifications\SiteInstallationSucceed;
|
use App\Notifications\SiteInstallationSucceed;
|
||||||
use App\ValidationRules\DomainRule;
|
use App\ValidationRules\DomainRule;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@ -34,6 +35,7 @@ public function create(Server $server, array $input): Site
|
|||||||
'type' => $input['type'],
|
'type' => $input['type'],
|
||||||
'domain' => $input['domain'],
|
'domain' => $input['domain'],
|
||||||
'aliases' => $input['aliases'] ?? [],
|
'aliases' => $input['aliases'] ?? [],
|
||||||
|
'port' => $input['port'] ?? null,
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'path' => '/home/'.$user.'/'.$input['domain'],
|
'path' => '/home/'.$user.'/'.$input['domain'],
|
||||||
'status' => SiteStatus::INSTALLING,
|
'status' => SiteStatus::INSTALLING,
|
||||||
@ -127,6 +129,14 @@ public static function rules(Server $server, array $input): array
|
|||||||
Rule::unique('sites', 'user')->where('server_id', $server->id),
|
Rule::unique('sites', 'user')->where('server_id', $server->id),
|
||||||
Rule::notIn($server->getSshUsers()),
|
Rule::notIn($server->getSshUsers()),
|
||||||
],
|
],
|
||||||
|
'port' => [
|
||||||
|
'nullable',
|
||||||
|
'integer',
|
||||||
|
'min:1',
|
||||||
|
'max:65535',
|
||||||
|
Rule::unique('sites', 'port')
|
||||||
|
->where(fn (Builder $query) => $query->where('server_id', $server->id))
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
return array_merge($rules, self::typeRules($server, $input));
|
return array_merge($rules, self::typeRules($server, $input));
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
use Filament\Forms\Set;
|
use Filament\Forms\Set;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Support\Enums\MaxWidth;
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
use Illuminate\Support\HtmlString;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Index extends \App\Web\Pages\Servers\Page
|
class Index extends \App\Web\Pages\Servers\Page
|
||||||
@ -84,6 +85,14 @@ protected function getHeaderActions(): array
|
|||||||
->options(collect($this->server->installedPHPVersions())->mapWithKeys(fn ($version) => [$version => $version]))
|
->options(collect($this->server->installedPHPVersions())->mapWithKeys(fn ($version) => [$version => $version]))
|
||||||
->visible(fn (Get $get): bool => isset(CreateSite::rules($this->server, $get())['php_version']))
|
->visible(fn (Get $get): bool => isset(CreateSite::rules($this->server, $get())['php_version']))
|
||||||
->rules(fn (Get $get) => CreateSite::rules($this->server, $get())['php_version']),
|
->rules(fn (Get $get) => CreateSite::rules($this->server, $get())['php_version']),
|
||||||
|
TextInput::make('port')
|
||||||
|
->placeholder('Reverse Proxy Port')
|
||||||
|
->rules(fn (Get $get) => CreateSite::rules($this->server, $get())['port'])
|
||||||
|
->helperText(
|
||||||
|
new HtmlString(
|
||||||
|
'The port to use for the reverse proxy (<a href="https://vitodeploy.com/docs/sites/create" class="text-primary-500" target="_blank">Read more</a>)'
|
||||||
|
)
|
||||||
|
),
|
||||||
TextInput::make('web_directory')
|
TextInput::make('web_directory')
|
||||||
->placeholder('For / leave empty')
|
->placeholder('For / leave empty')
|
||||||
->rules(fn (Get $get) => CreateSite::rules($this->server, $get())['web_directory'])
|
->rules(fn (Get $get) => CreateSite::rules($this->server, $get())['web_directory'])
|
||||||
|
@ -66,16 +66,6 @@ public function getSecondSubNavigation(): array
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->can('update', [$this->site, $this->server])) {
|
|
||||||
$items[] = NavigationItem::make(Settings::getNavigationLabel())
|
|
||||||
->icon('heroicon-o-wrench-screwdriver')
|
|
||||||
->isActiveWhen(fn () => request()->routeIs(Settings::getRouteName()))
|
|
||||||
->url(Settings::getUrl(parameters: [
|
|
||||||
'server' => $this->server,
|
|
||||||
'site' => $this->site,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($user->can('view', [Redirect::class, $this->site, $this->server])) {
|
if ($user->can('view', [Redirect::class, $this->site, $this->server])) {
|
||||||
$items[] = NavigationItem::make(Pages\Redirects\Index::getNavigationLabel())
|
$items[] = NavigationItem::make(Pages\Redirects\Index::getNavigationLabel())
|
||||||
->icon('heroicon-o-arrows-right-left')
|
->icon('heroicon-o-arrows-right-left')
|
||||||
@ -86,6 +76,16 @@ public function getSecondSubNavigation(): array
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($user->can('update', [$this->site, $this->server])) {
|
||||||
|
$items[] = NavigationItem::make(Settings::getNavigationLabel())
|
||||||
|
->icon('heroicon-o-wrench-screwdriver')
|
||||||
|
->isActiveWhen(fn () => request()->routeIs(Settings::getRouteName()))
|
||||||
|
->url(Settings::getUrl(parameters: [
|
||||||
|
'server' => $this->server,
|
||||||
|
'site' => $this->site,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
NavigationGroup::make()
|
NavigationGroup::make()
|
||||||
->items($items),
|
->items($items),
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
@if ($site->activeSsl && $site->force_ssl)
|
@if ($site->activeSsl && $site->force_ssl)
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name {{ $site->domain }} {{ $site->getAliasesString() }};
|
server_name {{ $site->domain }} {{ $site->getAliasesString() }};
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
}
|
}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@php
|
@php
|
||||||
@ -51,31 +51,41 @@
|
|||||||
|
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
|
|
||||||
@if ($site->type()->language() === 'php')
|
@if ($site->port)
|
||||||
@php
|
|
||||||
$phpSocket = "unix:/var/run/php/php{$site->php_version}-fpm.sock";
|
|
||||||
if ($site->isIsolated()) {
|
|
||||||
$phpSocket = "unix:/run/php/php{$site->php_version}-fpm-{$site->user}.sock";
|
|
||||||
}
|
|
||||||
@endphp
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.php?$query_string;
|
proxy_pass http://127.0.0.1:{{ $site->port }};
|
||||||
}
|
proxy_set_header Host $host;
|
||||||
location ~ \.php$ {
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
fastcgi_pass {{ $phpSocket }};
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
include fastcgi_params;
|
|
||||||
fastcgi_hide_header X-Powered-By;
|
|
||||||
}
|
}
|
||||||
|
@else
|
||||||
|
@if ($site->type()->language() === 'php')
|
||||||
|
@php
|
||||||
|
$phpSocket = "unix:/var/run/php/php{$site->php_version}-fpm.sock";
|
||||||
|
if ($site->isIsolated()) {
|
||||||
|
$phpSocket = "unix:/run/php/php{$site->php_version}-fpm-{$site->user}.sock";
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
|
}
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_pass {{ $phpSocket }};
|
||||||
|
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_hide_header X-Powered-By;
|
||||||
|
}
|
||||||
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
|
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://{{ $backendName }}$request_uri;
|
proxy_pass http://{{ $backendName }}$request_uri;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user