Skip to content

Commit

Permalink
Merge pull request #913 from drbyte/valet-proxy
Browse files Browse the repository at this point in the history
Add proxy site-handling commands
  • Loading branch information
mattstauffer authored Apr 30, 2020
2 parents c9f3b14 + 4043fd6 commit 73b16c0
Show file tree
Hide file tree
Showing 8 changed files with 977 additions and 41 deletions.
259 changes: 220 additions & 39 deletions cli/Valet/Site.php

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions cli/stubs/proxy.valet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# valet stub: proxy.valet.conf

server {
listen 127.0.0.1:80;
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
return 301 https://$host$request_uri;
}

server {
listen 127.0.0.1:443 ssl http2;
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
root /;
charset utf-8;
client_max_body_size 128M;
http2_push_preload on;

location /VALET_STATIC_PREFIX/ {
internal;
alias /;
try_files $uri $uri/;
}

ssl_certificate "VALET_CERT";
ssl_certificate_key "VALET_KEY";

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

access_log off;
error_log "VALET_HOME_PATH/Log/VALET_SITE-error.log";

error_page 404 "VALET_SERVER_PATH";

location / {
proxy_pass VALET_PROXY_HOST;
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_set_header X-Client-Verify SUCCESS;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
chunked_transfer_encoding on;
proxy_redirect off;
proxy_buffering off;
}

location ~ /\.ht {
deny all;
}
}

server {
listen 127.0.0.1:60;
server_name VALET_SITE www.VALET_SITE *.VALET_SITE;
root /;
charset utf-8;
client_max_body_size 128M;

add_header X-Robots-Tag 'noindex, nofollow, nosnippet, noarchive';

location /VALET_STATIC_PREFIX/ {
internal;
alias /;
try_files $uri $uri/;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

access_log off;
error_log "VALET_HOME_PATH/Log/VALET_SITE-error.log";

error_page 404 "VALET_SERVER_PATH";

location / {
proxy_pass VALET_PROXY_HOST;
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;
}

location ~ /\.ht {
deny all;
}
}

29 changes: 29 additions & 0 deletions cli/valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,35 @@
info('The ['.$url.'] site will now serve traffic over HTTP.');
})->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');

/**
* Create an Nginx proxy config for the specified domain
*/
$app->command('proxy domain host', function ($domain, $host) {

Site::proxyCreate($domain, $host);
Nginx::restart();

})->descriptions('Create an Nginx proxy site for the specified host. Useful for docker, mailhog etc.');

/**
* Delete an Nginx proxy config
*/
$app->command('unproxy domain', function ($domain) {

Site::proxyDelete($domain);
Nginx::restart();

})->descriptions('Delete an Nginx proxy config.');

/**
* Display all of the sites that are proxies.
*/
$app->command('proxies', function () {
$proxies = Site::proxies();

table(['Site', 'SSL', 'URL', 'Host'], $proxies->all());
})->descriptions('Display all of the proxy sites');

/**
* Determine which Valet driver the current directory is using.
*/
Expand Down
Loading

0 comments on commit 73b16c0

Please sign in to comment.