
When developing and maintaining a large number of sites, the creation of virtual hosts on a local machine takes some time.
Alternatively, you can
update the apache configs and the hosts file with
scripts .
')
Another solution is to set up your own DNS server with a top-level zone.
This is what we will do now.
So, create the zone ".dev" (using the named and apache daemon under FreeBSD)
Edit the /etc/namedb/named.conf file:
options {
directory "/ etc / namedb";
pid-file "/ var / run / named / pid";
dump-file "/var/dump/named_dump.db";
statistics-file "/var/stats/named.stats";
// external DNS
// specify your current DNS
// or the server of the company <s> evil </ s> good:
forwarders {8.8.8.8; };
};
// our zone
zone "dev" {type master; file "master / dev"; };
Create a new zone file / var / named / etc / namedb / master / dev:
$ TTL 3600; 1 hour
dev. IN SOA ns1.dev. admin.www.dev (
2009112601; Serial
10800; Refresh
3600; Retry
604800; Expire
86400; Minimum TTL
)
; DNS Servers
IN NS ns1.dev
IN A 127.0.0.1
; Machine names
ns1 IN A 127.0.0.1
* IN A 127.0.0.1
After restarting namedb and specifying 127.0.0.1 as your DNS (/etc/resolv.conf),
any .dev address will lead to 127.0.0.1.
Trying?
% dig any address .dev
...
;; ANSWER SECTION:
\ 208 \ 187 \ 209 \ 142 \ 208 \ 177 \ 208 \ 190 \ 208 \ 185- \ 208 \ 176 \ 208 \ 180 \ 209 \ 128 \ 208 \ 181 \ 209 \ 129.dev. 3600 IN A 127.0.0.1
...
% ping waka.dev ~
PING waka.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq = 0 ttl = 64 time = 0.024 ms
^ C
Now you need to teach apache. In httpd.conf we write to the end of the file:
UseCanonicalName Off
VirtualDocumentRoot / www /% - 1 /% - 2
After restarting apache, type in the browser address
http://habrahabr.dev/ - apache will issue /www/dev/habrahabr/index.html
We create this file in advance (otherwise, we will get an error 404) and allow access to / www / dev / (otherwise we will get an error 403) in httpd.conf:
<Directory "/ www / dev /">
Options Indexes Includes FollowSymLinks
AllowOverride All
Allow from all
</ Directory>
Other computers
Additionally, you can make this scheme available in virtual machines and in the local network. To do this, in the / etc / namedb / master / dev file, change 127.0.0.1 to the IP address of your computer and specify it as the DNS on the necessary computers.
Web Studio
In the company where you work, for each employee you can configure your domain level 1 or 2 using one DNS server.
Oh!
- Apache incorrectly transmits DOCUMENT_ROOT to cgi or mod_php.
Instead of the computed VirtualDocumentRoot, it passes the DocumentRoot specified in httpd.conf.
Keep this in mind when using this variable.
- Modern browsers combine the address bar and search bar. If you transfer to the search results after entering the domain, enter the domain with a slash (/) at the end, for example, waka.dev/
Links
Apache: Dynamically Configured Bulk Virtual Hosting