Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion cli/Valet/Nginx.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace Valet;

use DomainException;

class Nginx
{
var $brew;
var $cli;
var $files;
var $configuration;
var $site;
const NGINX_CONF = '/usr/local/etc/nginx/nginx.conf';

/**
* Create a new Nginx instance.
Expand Down Expand Up @@ -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)
);
}
Expand Down Expand Up @@ -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.
*
Expand All @@ -122,6 +138,8 @@ function rewriteSecureNginxFiles()
*/
function restart()
{
$this->lint();

$this->brew->restartService($this->brew->nginxServiceName());
}

Expand Down