Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Run Nginx on WSL (Ubuntu on Windows) with automatic domain names and environment for local development
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_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param FUEL_ENV $environment;
include fastcgi_params;
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
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:
listen =
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

This comment has been minimized.

Copy link
Owner Author

@willpower232 willpower232 commented Dec 8, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment