Last active
February 3, 2020 16:06
-
-
Save richardfeliciano/d48e59d6da9f6127ab04b0e72d5d94a6 to your computer and use it in GitHub Desktop.
Generate a laradock/nginx configuration for a single project it helps you to configure your projects a little bit faster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* --host: host example.dev | |
* --path: project-name/ | |
* --company: company name if you want to use SSL | |
* --country: country name if you want to use SSL | |
**/ | |
$args = getopt(null, ["host:", "path:", "company:", "country:"]); | |
$file = file_get_contents('./nginx/sites/app.conf.example'); | |
$host = $args['host']; | |
$filename = './nginx/sites/' . $host . '.conf'; | |
$data = str_replace([ | |
'server_name localhost;', | |
'root /var/www/public', | |
'ssl_certificate /etc/nginx/ssl/default.crt;', | |
'ssl_certificate_key /etc/nginx/ssl/default.key;', | |
], [ | |
'server_name ' . $args["host"] . ';', | |
'root /var/www/' . $args["path"], | |
'ssl_certificate /etc/nginx/ssl/' . $host . '.crt;', | |
'ssl_certificate_key /etc/nginx/ssl/' . $host . '.key;', | |
], $file); | |
file_put_contents($filename, $data); | |
exec('openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=' . $args['company'] . ', Inc./CN=' . $host . '" -addext "subjectAltName=DNS:' . $host . '" -newkey rsa:2048 -keyout ./nginx/ssl/' . $host . '.key -out ./nginx/ssl/' . $host . '.crt;'); | |
exec('docker-compose restart'); | |
#USAGE | |
php generator.php --host=hostname.dev --path=path/to/your/project/public --company=company --country=BR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment