Last active
May 20, 2023 15:23
-
-
Save willpower232/3205bf38fd6a0dcad7f01c3fd99b2ad0 to your computer and use it in GitHub Desktop.
Run Nginx on WSL (Ubuntu on Windows) with automatic domain names and environment for local development
This file contains 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
server { | |
listen 80; | |
listen 443 ssl http2; | |
# make yourself an SSL certificate for *.test.test (and your dhparam file if you're so inclined) | |
ssl_certificate /etc/nginx/ssl/test.cert; | |
ssl_certificate_key /etc/nginx/ssl/test.key; | |
# your other favourite SSL settings go here | |
server_name ~((?<environment>[\w-]+)\.)?(?<domain>[\w-]+)\.test\.test$; | |
root /mnt/c/path/to/your/websites/$domain/html; | |
if ($environment = '') { | |
set $environment development; | |
} | |
index index.php; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_param FUEL_ENV $environment; | |
include fastcgi_params; | |
} | |
} |
This file contains 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
#!/bin/bash | |
mkdir /etc/nginx/ssl && cd /etc/nginx/ssl | |
openssl req -new -x509 -nodes -sha256 -days 3650 -newkey rsa:2048 -keyout test.key -out test.cert -subj "/CN=*.test.test" -extensions SAN -config <( | |
cat <<-EOF | |
[req] | |
distinguished_name=dn | |
[dn] | |
CN=*.test.test | |
[SAN] | |
subjectAltName=DNS:*.test.test | |
EOF | |
) |
This file contains 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
[test] | |
user = www-data | |
group = www-data | |
; WSL (Ubuntu on Windows) currently has problems with socket ownership so use the port instead | |
; you should also disable, remove, or replace the default pool config to avoid errors in your PHP log | |
; related: https://github.com/Microsoft/WSL/issues/393#issuecomment-284755257 | |
listen = 127.0.0.1:9000 | |
pm = dynamic | |
pm.max_children = 5 | |
pm.start_servers = 2 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chrome 63 officially HSTS'es the .dev domain so better to use .test instead
If you're using a certificate, Chrome will not automatically trust a wildcard TLD so I've gone with .test.test. The certificate can then be imported to your computer certificate store under Trusted Root Certification Authorities.