mirror of
https://github.com/laravel/valet.git
synced 2026-02-04 16:10:08 +01:00
🐛 Fixing Nginx configuration.
✨ Adding alias generation and launch daemon generation.
This commit is contained in:
@@ -75,14 +75,12 @@ function installServer()
|
||||
{
|
||||
$this->files->ensureDirExists(BREW_PREFIX.'/etc/nginx/valet');
|
||||
|
||||
$loopback = $this->configuration->read()['loopback'];
|
||||
|
||||
$this->files->putAsUser(
|
||||
BREW_PREFIX.'/etc/nginx/valet/valet.conf',
|
||||
str_replace(
|
||||
['VALET_LOOPBACK', 'VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'],
|
||||
[$loopback, VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX],
|
||||
$this->files->get(__DIR__.'/../stubs/valet.conf')
|
||||
['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'],
|
||||
[VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX],
|
||||
$this->replaceLoopback($this->files->get(__DIR__.'/../stubs/valet.conf'))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -92,6 +90,23 @@ function installServer()
|
||||
);
|
||||
}
|
||||
|
||||
function replaceLoopback($siteConf)
|
||||
{
|
||||
$loopback = $this->configuration->read()['loopback'];
|
||||
|
||||
if ($loopback === VALET_LOOPBACK) {
|
||||
return $siteConf;
|
||||
}
|
||||
|
||||
$str = '#listen VALET_LOOPBACK:80 default_server; # valet loopback';
|
||||
|
||||
return str_replace(
|
||||
$str,
|
||||
substr(str_replace('VALET_LOOPBACK', $loopback, $str), 1),
|
||||
$siteConf
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the Nginx configuration directory to the ~/.config/valet directory.
|
||||
*
|
||||
|
||||
@@ -424,15 +424,26 @@ function resecureForNewLoopback($oldLoopback, $loopback)
|
||||
*/
|
||||
function replaceOldLoopbackWithNew($siteConf, $old, $new)
|
||||
{
|
||||
$shouldComment = $new === VALET_LOOPBACK;
|
||||
|
||||
$lookups = [];
|
||||
$lookups[] = '~listen .*:80;~';
|
||||
$lookups[] = '~listen .*:443 ssl http2;~';
|
||||
$lookups[] = '~listen .*:60;~';
|
||||
$lookups[] = '~#?listen .*:80; # valet loopback~';
|
||||
$lookups[] = '~#?listen .*:443 ssl http2; # valet loopback~';
|
||||
$lookups[] = '~#?listen .*:60; # valet loopback~';
|
||||
|
||||
foreach ($lookups as $lookup) {
|
||||
preg_match($lookup, $siteConf, $matches);
|
||||
foreach ($matches as $match) {
|
||||
$replaced = str_replace($old, $new, $match);
|
||||
|
||||
if ($shouldComment && strpos($replaced, '#') !== 0) {
|
||||
$replaced = '#'.$replaced;
|
||||
}
|
||||
|
||||
if (! $shouldComment) {
|
||||
$replaced = ltrim($replaced, '#');
|
||||
}
|
||||
|
||||
$siteConf = str_replace($match, $replaced, $siteConf);
|
||||
}
|
||||
}
|
||||
@@ -752,6 +763,62 @@ function proxyDelete($url)
|
||||
info('Valet will no longer proxy [https://'.$url.'].');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old loopback interface alias and new one if necessary.
|
||||
*
|
||||
* @param string $oldLoopback
|
||||
* @param string $loopback
|
||||
* @return void
|
||||
*/
|
||||
function aliasLoopback($oldLoopback, $loopback)
|
||||
{
|
||||
if ($oldLoopback !== VALET_LOOPBACK) {
|
||||
$this->cli->run(sprintf(
|
||||
'sudo ifconfig lo0 -alias %s', $oldLoopback
|
||||
));
|
||||
|
||||
info('Old loopback interface alias removed ['.$oldLoopback.']');
|
||||
}
|
||||
|
||||
if ($loopback !== VALET_LOOPBACK) {
|
||||
$this->cli->run(sprintf(
|
||||
'sudo ifconfig lo0 alias %s', $loopback
|
||||
));
|
||||
|
||||
info('New loopback interface alias added ['.$loopback.']');
|
||||
}
|
||||
|
||||
$this->updatePlist($loopback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old LaunchDaemon and create a new one if necessary.
|
||||
*
|
||||
* @param string $loopback
|
||||
* @return void
|
||||
*/
|
||||
function updatePlist($loopback)
|
||||
{
|
||||
if ($this->files->exists($this->plistPath())) {
|
||||
$this->files->unlink($this->plistPath());
|
||||
|
||||
info('Old plist file removed ['.$this->plistPath().']');
|
||||
}
|
||||
|
||||
if ($loopback !== VALET_LOOPBACK) {
|
||||
$this->files->put(
|
||||
$this->plistPath(),
|
||||
str_replace(
|
||||
'VALET_LOOPBACK',
|
||||
$loopback,
|
||||
$this->files->get(__DIR__.'/../stubs/ifconfig.plist')
|
||||
)
|
||||
);
|
||||
|
||||
info('New plist file added ['.$this->plistPath().']');
|
||||
}
|
||||
}
|
||||
|
||||
function valetHomePath()
|
||||
{
|
||||
return VALET_HOME_PATH;
|
||||
@@ -762,6 +829,16 @@ function valetLoopback()
|
||||
return $this->config->read()['loopback'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to loopback LaunchDaemon.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function plistPath()
|
||||
{
|
||||
return '/Library/LaunchDaemons/com.laravel.valet.ifconfig.plist';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to Nginx site configuration files.
|
||||
*/
|
||||
|
||||
17
cli/stubs/ifconfig.plist
Normal file
17
cli/stubs/ifconfig.plist
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.laravel.valet.ifconfig</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/sbin/ifconfig</string>
|
||||
<string>lo0</string>
|
||||
<string>alias</string>
|
||||
<string>VALET_LOOPBACK</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,13 +1,15 @@
|
||||
# valet stub: proxy.valet.conf
|
||||
|
||||
server {
|
||||
listen VALET_LOOPBACK:80;
|
||||
listen 127.0.0.1:80;
|
||||
#listen VALET_LOOPBACK:80; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen VALET_LOOPBACK:443 ssl http2;
|
||||
listen 127.0.0.1:443 ssl http2;
|
||||
#listen VALET_LOOPBACK:443 ssl http2; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
root /;
|
||||
charset utf-8;
|
||||
@@ -55,7 +57,8 @@ server {
|
||||
}
|
||||
|
||||
server {
|
||||
listen VALET_LOOPBACK:60;
|
||||
listen 127.0.0.1:60;
|
||||
#listen VALET_LOOPBACK:60; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
root /;
|
||||
charset utf-8;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
server {
|
||||
listen VALET_LOOPBACK:80;
|
||||
listen 127.0.0.1:80;
|
||||
#listen VALET_LOOPBACK:80; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen VALET_LOOPBACK:443 ssl http2;
|
||||
listen 127.0.0.1:443 ssl http2;
|
||||
#listen VALET_LOOPBACK:443 ssl http2; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
root /;
|
||||
charset utf-8;
|
||||
@@ -48,7 +50,8 @@ server {
|
||||
}
|
||||
|
||||
server {
|
||||
listen VALET_LOOPBACK:60;
|
||||
listen 127.0.0.1:60;
|
||||
#listen VALET_LOOPBACK:60; # valet loopback
|
||||
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
|
||||
root /;
|
||||
charset utf-8;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
server {
|
||||
listen VALET_LOOPBACK:80 default_server;
|
||||
listen 127.0.0.1:80 default_server;
|
||||
#listen VALET_LOOPBACK:80 default_server; # valet loopback
|
||||
root /;
|
||||
charset utf-8;
|
||||
client_max_body_size 128M;
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
Configuration::updateKey('loopback', $loopback = trim($loopback, '.'));
|
||||
|
||||
DnsMasq::refreshConfiguration();
|
||||
Site::aliasLoopback($oldLoopback, $loopback);
|
||||
Site::resecureForNewLoopback($oldLoopback, $loopback);
|
||||
Nginx::installServer();
|
||||
PhpFpm::restart();
|
||||
|
||||
Reference in New Issue
Block a user