How to put wildcard entry into /etc/hosts?

后端 未结 3 996
自闭症患者
自闭症患者 2020-11-30 23:47

I recently wanted to point all subdomains for a test domain, let\'s say example.com to the localhost. Is there a way to point all requests on *.example.com to resolve to 127

3条回答
  •  有刺的猬
    2020-12-01 00:14

    Here is the configuration for those trying to accomplish the original goal (wildcards all pointing to same codebase -- install nothing, dev environment ie, XAMPP)

    hosts file (add an entry)

    file: /etc/hosts (non-windows)

    127.0.0.1   example.local
    

    httpd.conf configuration (enable vhosts)

    file: /XAMPP/etc/httpd.conf

    # Virtual hosts
    Include etc/extra/httpd-vhosts.conf
    

    httpd-vhosts.conf configuration

    file: XAMPP/etc/extra/httpd-vhosts.conf

    
        ServerAdmin admin@example.local
        DocumentRoot "/path_to_XAMPP/htdocs"
        ServerName example.local
        ServerAlias *.example.local
    #    SetEnv APP_ENVIRONMENT development
    #    ErrorLog "logs/example.local-error_log"
    #    CustomLog "logs/example.local-access_log" common
    
    

    restart apache

    create pac file:

    save as whatever.pac wherever you want to and then load the file in the browser's network>proxy>auto_configuration settings (reload if you alter this)

    function FindProxyForURL(url, host) {
      if (shExpMatch(host, "*example.local")) {
        return "PROXY example.local";
      }
      return "DIRECT";
    }
    

提交回复
热议问题