Skip to content

Instantly share code, notes, and snippets.

@morales2k
Last active December 14, 2017 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morales2k/bce5e4af2cd0b6a97737c78c13d7367e to your computer and use it in GitHub Desktop.
Save morales2k/bce5e4af2cd0b6a97737c78c13d7367e to your computer and use it in GitHub Desktop.
For use with Laravel Homestead. Set a server_name to add for ngrok (or similar services, but my useccase is ngrok.) With this type of setup, I can use Homestead globally (only one vm for many sites) and add an additional domain for ngrok on the sites I wish to load it with.
---
ip: "10.10.192.168"
memory: 2048
cpus: 1
provider: virtualbox
name: homestead-7
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www
to: /home/vagrant/Code
sites:
- map: mydev.test
to: /home/vagrant/Code/test/public
type: ngrokEnabled
params:
- key: ngrokName
value: {WHATEVER_YOU_WANT_TO_USE}.ngrok.io
databases:
- Homestead
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
#!/usr/bin/env bash
###
# Homestead/scripts/serve-ngrokEnabled.sh
###
# This is a copy, basically, of the serve-laravel.sh script,
# but modded to look for my custom param (ngrokName) and
# add it to server_name if it exists. This will only
# execute on sites that are of type: ngrokEnabled
###
# The ngrok command I use to run share these sites is as follows:
# ngrok http mydev.test:80 --subdomain={WHATEVER_YOU_WANT_TO_USE}
###
declare -A params=$6 # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
fastcgi_param ${element} ${params[$element]};"
done
fi
if test "${params['ngrokName']+isset}"
then
echo "${params[ngrokName]} will be added to \"$1\" server name"
else
params['ngrokName']=""
fi
block="server {
listen ${3:-80};
listen ${4:-443} ssl http2;
server_name $1 ${params[ngrokName]};
root \"$2\";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
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 /var/log/nginx/$1-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php$5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
$paramsTXT
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/$1.crt;
ssl_certificate_key /etc/nginx/ssl/$1.key;
}
"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment