mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 01:00:09 +01:00
Check nginx.conf for errors before restarting nginx
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Valet;
|
namespace Valet;
|
||||||
|
|
||||||
|
use DomainException;
|
||||||
|
|
||||||
class Nginx
|
class Nginx
|
||||||
{
|
{
|
||||||
var $brew;
|
var $brew;
|
||||||
@@ -9,6 +11,7 @@ class Nginx
|
|||||||
var $files;
|
var $files;
|
||||||
var $configuration;
|
var $configuration;
|
||||||
var $site;
|
var $site;
|
||||||
|
const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Nginx instance.
|
* Create a new Nginx instance.
|
||||||
@@ -56,7 +59,7 @@ function installConfiguration()
|
|||||||
$contents = $this->files->get(__DIR__.'/../stubs/nginx.conf');
|
$contents = $this->files->get(__DIR__.'/../stubs/nginx.conf');
|
||||||
|
|
||||||
$this->files->putAsUser(
|
$this->files->putAsUser(
|
||||||
'/usr/local/etc/nginx/nginx.conf',
|
static::NGINX_CONF,
|
||||||
str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents)
|
str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -103,6 +106,19 @@ function installNginxDirectory()
|
|||||||
$this->rewriteSecureNginxFiles();
|
$this->rewriteSecureNginxFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check nginx.conf for errors.
|
||||||
|
*/
|
||||||
|
private function lint()
|
||||||
|
{
|
||||||
|
$this->cli->quietly(
|
||||||
|
'sudo nginx -c '.static::NGINX_CONF.' -t',
|
||||||
|
function($exitCode, $outputMessage) {
|
||||||
|
throw new DomainException("Nginx cannot start, please check your nginx.conf [$exitCode: $outputMessage].");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate fresh Nginx servers for existing secure sites.
|
* Generate fresh Nginx servers for existing secure sites.
|
||||||
*
|
*
|
||||||
@@ -122,6 +138,8 @@ function rewriteSecureNginxFiles()
|
|||||||
*/
|
*/
|
||||||
function restart()
|
function restart()
|
||||||
{
|
{
|
||||||
|
$this->lint();
|
||||||
|
|
||||||
$this->brew->restartService($this->brew->nginxServiceName());
|
$this->brew->restartService($this->brew->nginxServiceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user