mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 16:50:09 +01:00
Check nginx.conf for errors before restarting nginx
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Valet;
|
||||
|
||||
use DomainException;
|
||||
|
||||
class Nginx
|
||||
{
|
||||
var $brew;
|
||||
@@ -9,6 +11,7 @@ class Nginx
|
||||
var $files;
|
||||
var $configuration;
|
||||
var $site;
|
||||
const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf';
|
||||
|
||||
/**
|
||||
* Create a new Nginx instance.
|
||||
@@ -56,7 +59,7 @@ function installConfiguration()
|
||||
$contents = $this->files->get(__DIR__.'/../stubs/nginx.conf');
|
||||
|
||||
$this->files->putAsUser(
|
||||
'/usr/local/etc/nginx/nginx.conf',
|
||||
static::NGINX_CONF,
|
||||
str_replace(['VALET_USER', 'VALET_HOME_PATH'], [user(), VALET_HOME_PATH], $contents)
|
||||
);
|
||||
}
|
||||
@@ -103,6 +106,19 @@ function installNginxDirectory()
|
||||
$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.
|
||||
*
|
||||
@@ -122,6 +138,8 @@ function rewriteSecureNginxFiles()
|
||||
*/
|
||||
function restart()
|
||||
{
|
||||
$this->lint();
|
||||
|
||||
$this->brew->restartService($this->brew->nginxServiceName());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user