Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jnx/d14df945c688656e6069b4652570ead8 to your computer and use it in GitHub Desktop.
Save jnx/d14df945c688656e6069b4652570ead8 to your computer and use it in GitHub Desktop.
Getting some equivalent of pow.cx using nginx and dnsmasq on non-Apple *NIX

Install nginx and dnsmasq

Using apt-get/dnf/pkg_add/ports/rpm/pacman/whatever...

Add necessary config files

/etc/dnsmasq.d/dev

# /etc/dnsmasq.d/dev
# Have dnsmasq resolv *.dev domains to localhost
address=/dev/127.0.0.1

/etc/nginx/sites-available/dev.conf

# /etc/nginx/sites-available/dev.conf
server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  
  server_name "~^(?<app>\w+)\.dev";
  
  location ~ / {
    proxy_pass http://unix:/tmp/$app.sock;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
  }
}

Link nginx dev domain to sites-enabled

 `sudo ln -s /etc/nginx/sites-available/dev.conf /etc/nginx/sites-enabled/`

Restart/reload services

sudo service dnsmasq restart
sudo nginx -t && nginx -s reload

Start a web app configured to listen to a unix socket

Heres is an example using puma to start a rack application: puma -b unix:///tmp/my_app.sock.

Any way of starting a web application that makes it listen on a socket should do fine.

Visit http://my_app.dev

...now get back to coding :)

# /etc/dnsmasq.d/dev
# Have dnsmasq resolv *.dev domains to localhost
address=/dev/127.0.0.1
# /etc/nginx/sites-available/dev.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name "~^(?<app>\w+)\.dev";
location ~ / {
proxy_pass http://unix:/tmp/$app.sock;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment