\"http://192.168.0.1\" i.e开发者_Python百科. I want to redirect any request other than \"192.168.0.1\" to \"http://192.168.0.1\"" />
开发者

How to redirect to a default hostname

I want something like:

"http://www.anyhostname.com" ==> "http://192.168.0.1"

i.e开发者_Python百科. I want to redirect any request other than "192.168.0.1" to "http://192.168.0.1"

I am using Lighttpd as my webserver and dnsmasq as my DNS server.


I have to wonder if you're doing transparent proxying -- if so, there may be better mechanisms to accomplish what you want to do than literally doing what you outlined as your goal.

But if you want to keep going this route, I think you can use lighttpd's mod_evhost facility to easily use a default site configuration:

General Example:

server.document-root = "/home/user/sites/default/site"   
evhost.path-pattern  = "/home/user/sites/%0/site/" 

If example.org is requested, and /home/user/sites/example.org/site/ is found, that path becomes the docroot.

If example.net is requested but no directory named /home/user/sites/example.net/site/ exists, then the docroot remains /home/user/sites/default/site

If you have specific hostnames that you want to handle, you can add them to /etc/hosts and your dnsmasq will serve them. This would work if you had a few hundred hosts/domains that you wanted to handle, but if you wanted to handle everything, then dnsmasq may not be the right tool.

I know that PowerDNS's PipeBackend can be used to easily give the same answer regardless of DNS question; this way, you could easily intercept requests and handle some or all requests specially. This way, you could answer 192.168.0.1 for every request, for some requests, or anything you can program.


Okay, I solved the problem. Posting the solution here back with hope that it helps somebody in the future...

I solved this by modifying the lighttpd.conf file. I added the following inside my lighttpd.conf file:

$HTTP["host"] !~ "mydesiredhostname\.com" {
        url.redirect = (
                                "" => "http://192.168.0.1/"
                        )
}

Thank you everybody for your time. Cheers!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜