How to resolve local domain names?

recently do a local website, the domain name resources of the website: www.example.com, m.example.com img.example.com. If you can"t use Ip access, you want to access resources locally through a domain name.
first consider modifying the hosts file in the windows system:

127.0.0.1 www.example.com
127.0.0.1 m.example.com
127.0.0.1 img.example.com

obviously, the above method can only ensure that one domain name can be accessed normally, and nothing else can be accessed.
is there any software in WIN environment that can be redirected?

Mar.04,2021

are you sure obviously the above method can only ensure that one domain name can be accessed properly, and nothing else can be accessed. ?
Ngnix's server_name can put multiple domain names

server {
    listen       80;
    server_name  www.example.com m.example.com;
    
    // ...
}    

if the apache server uses vhosts.conf to configure multi-site
if the nginx server modifies the nginx.conf file, for example:
server {

    listen       80;
    server_name  www.example.com;
    root    "D:/phpStudy/PHPTutorial/WWW";
    location / {
       index  index.html index.htm index.php l.php;
       autoindex  on;
    }

}


  1. Ngx change
  2. since it is local, you might as well try
  3. if gateway routing supports domain name redirection.

I misconfigured the local virtual host, and it is indeed possible. The host file is ready, and then the virtual host of ngx is configured with OK.
it would be better if https could be simulated locally


switchhost
Link: https://github.com/oldj/Switc.

Menu