Don't know where to look?

You can search all my notes here

Redirect all *.home-domains to localhost, without touching /etc/hosts

If you configured your Apache in a way that it automatically resolves all *.home-domains, you will most probably also want your dns to resolve these domains automatically without having to enter every domain into /etc/hosts. To achieve this, you can install a local dns-server and make it the default for *.home-domains.

Under macOS it’s best to install and use dnsmasq in the following way

  1. Install and update homebrew
  2. brew install dnsmasq

Enter the following commands into a terminal to configure dnsmasq: (source)

sh
# Copy the default configuration file.
cp $(brew list dnsmasq | grep /dnsmasq.conf.example$) /usr/local/etc/dnsmasq.conf
# Copy the daemon configuration file into place.
sudo cp $(brew list dnsmasq | grep /homebrew.mxcl.dnsmasq.plist$) /Library/LaunchDaemons/
# Start Dnsmasq automatically.
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Now add the following to the file /usr/local/etc/dnsmasq.conf:

apache_conf
address=/home/127.0.0.1

After three more commands the setup is complete:

sh
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
sudo tee /etc/resolver/home >/dev/null <<EOF
nameserver 127.0.0.1
EOF

After that all *.home-domains get redirected to localhost. All other domains will be resolved the way they where always resolved.

Use your virtual-hosts on other devices as well

I use the proxy-server SquidMan with the following config to enable my virtual-hosts on other devices as well:

apache_conf
# the parent cache
cache_peer %PARENTPROXY% parent %PARENTPORT% 7 no-query no-digest no-netdb-exchange default

# performance options
pipeline_prefetch %PIPELINE_PREFETCH%
cache_miss_revalidate %CACHE_MISS_REVALIDATE%
read_ahead_gap %READ_AHEAD_GAP%
cache_replacement_policy %CACHE_REPLACEMENT_POLICY%
memory_replacement_policy %MEMORY_REPLACEMENT_POLICY%

# disk and memory cache settings
cache_dir ufs %CACHEDIR% %CACHESIZE% 16 256
maximum_object_size %MAXOBJECTSIZE%
cache_mem %MEMCACHESIZE%
maximum_object_size_in_memory %MEMMAXOBJECTSIZE%

# store coredumps in the first cache dir
coredump_dir %CACHEDIR%

# the hostname squid displays in error messages
visible_hostname %VISIBLEHOSTNAME%

# log & process ID file details
cache_access_log stdio:%ACCESSLOG%
cache_store_log stdio:%STORELOG%
cache_log %CACHELOG%
pid_filename %PIDFILE%

# Squid listening port
http_port %PORT%

# Access Control lists
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT
%ALLOWEDHOSTS%
%DIRECTHOSTS%

# Only allow cachemgr access from localhost
http_access allow localhost manager 
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# protect web apps running on the proxy host from external users
http_access allow to_localhost

# rules for client access go here
http_access allow localhost
%HTTPACCESSALLOWED%

# after allowed hosts, deny all other access to this proxy
# don't list any other access settings below this point
http_access allow all

# specify which hosts have direct access (bypassing the parent proxy)
%ALWAYSDIRECT%
always_direct deny all

# refresh patterns (squid-recommended)
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
refresh_pattern .		0	20%	4320

dns_nameservers 127.0.0.1 8.8.8.8 

If you configure Squidman this way and set your development-machine as a proxy on your other devices all your *.home domains will start working on these devices as well.

After starting Squid you can safely quit Squidman. The proxy-service will keep running.

Comments

Post-Meta