mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-08 01:12:34 +00:00
reverse proxy basics (#609)
This commit is contained in:
@ -2,6 +2,7 @@ import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, C
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { CommandIcon, SearchIcon } from 'lucide-react';
|
||||
import CreateServer from '@/pages/servers/components/create-server';
|
||||
|
||||
export default function AppCommand() {
|
||||
const [open, setOpen] = useState(false);
|
||||
@ -33,7 +34,9 @@ export default function AppCommand() {
|
||||
<CommandList>
|
||||
<CommandEmpty>No results found.</CommandEmpty>
|
||||
<CommandGroup heading="Suggestions">
|
||||
<CommandItem>Create server</CommandItem>
|
||||
<CreateServer>
|
||||
<CommandItem>Create server</CommandItem>
|
||||
</CreateServer>
|
||||
<CommandItem>Create project</CommandItem>
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
|
@ -47,7 +47,7 @@ function SheetContent({
|
||||
<SheetPrimitive.Content
|
||||
data-slot="sheet-content"
|
||||
className={cn(
|
||||
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500',
|
||||
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col overflow-y-auto shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500',
|
||||
side === 'right' &&
|
||||
'data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm',
|
||||
side === 'left' &&
|
||||
|
@ -25,6 +25,7 @@ type CreateSiteForm = {
|
||||
php_version: string;
|
||||
source_control: string;
|
||||
user: string;
|
||||
port: string;
|
||||
};
|
||||
|
||||
export default function CreateSite({ server, children }: { server?: Server; children: ReactNode }) {
|
||||
@ -39,6 +40,7 @@ export default function CreateSite({ server, children }: { server?: Server; chil
|
||||
php_version: '',
|
||||
source_control: '',
|
||||
user: '',
|
||||
port: '',
|
||||
});
|
||||
|
||||
const submit: FormEventHandler = (e) => {
|
||||
@ -154,6 +156,15 @@ export default function CreateSite({ server, children }: { server?: Server; chil
|
||||
<InputError message={form.errors.aliases} />
|
||||
</FormField>
|
||||
|
||||
<FormField>
|
||||
<Label htmlFor="port">Reverse proxy port</Label>
|
||||
<Input id="port" type="text" value={form.data.port} onChange={(e) => form.setData('port', e.target.value)} placeholder="3000" />
|
||||
<p className="text-muted-foreground text-xs">
|
||||
This port will be used for reverse proxying the site. It should be unique across all sites on the server.
|
||||
</p>
|
||||
<InputError message={form.errors.port} />
|
||||
</FormField>
|
||||
|
||||
{page.props.configs.site_types_custom_fields[form.data.type].map((config) => getFormField(config))}
|
||||
|
||||
<FormField>
|
||||
|
@ -8,17 +8,21 @@
|
||||
import access_log {{ $site->domain }}
|
||||
import compression
|
||||
import security_headers
|
||||
@if ($site->type()->language() === 'php')
|
||||
root * {{ $site->getWebDirectoryPath() }}
|
||||
@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
|
||||
try_files {path} {path}/ /index.php?{query}
|
||||
php_fastcgi {{ $phpSocket }}
|
||||
file_server
|
||||
@if ($site->port)
|
||||
reverse_proxy 127.0.0.1:{{ $site->port }}
|
||||
@else
|
||||
@if ($site->type()->language() === 'php')
|
||||
root * {{ $site->getWebDirectoryPath() }}
|
||||
@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
|
||||
try_files {path} {path}/ /index.php?{query}
|
||||
php_fastcgi {{ $phpSocket }}
|
||||
file_server
|
||||
@endif
|
||||
@endif
|
||||
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
|
||||
reverse_proxy {
|
||||
@ -44,4 +48,4 @@
|
||||
}
|
||||
@endif
|
||||
@include('ssh.services.webserver.caddy.redirects', ['site' => $site])
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user