mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-17 17:01: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\ValidationRules\DomainRule;
|
||||
use Exception;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@ -34,6 +35,7 @@ public function create(Server $server, array $input): Site
|
||||
'type' => $input['type'],
|
||||
'domain' => $input['domain'],
|
||||
'aliases' => $input['aliases'] ?? [],
|
||||
'port' => $input['port'] ?? null,
|
||||
'user' => $user,
|
||||
'path' => '/home/'.$user.'/'.$input['domain'],
|
||||
'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::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));
|
||||
|
@ -20,6 +20,7 @@
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Throwable;
|
||||
|
||||
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]))
|
||||
->visible(fn (Get $get): bool => isset(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')
|
||||
->placeholder('For / leave empty')
|
||||
->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])) {
|
||||
$items[] = NavigationItem::make(Pages\Redirects\Index::getNavigationLabel())
|
||||
->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 [
|
||||
NavigationGroup::make()
|
||||
->items($items),
|
||||
|
@ -1,9 +1,9 @@
|
||||
@if ($site->activeSsl && $site->force_ssl)
|
||||
server {
|
||||
listen 80;
|
||||
server_name {{ $site->domain }} {{ $site->getAliasesString() }};
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
server_name {{ $site->domain }} {{ $site->getAliasesString() }};
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
@endif
|
||||
|
||||
@php
|
||||
@ -51,31 +51,41 @@
|
||||
|
||||
charset utf-8;
|
||||
|
||||
@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
|
||||
@if ($site->port)
|
||||
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;
|
||||
proxy_pass http://127.0.0.1:{{ $site->port }};
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
@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
|
||||
|
||||
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
|
||||
location / {
|
||||
proxy_pass http://{{ $backendName }}$request_uri;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_pass http://{{ $backendName }}$request_uri;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
@endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user