Nginx and DNS

本文介绍如何在Ubuntu上配置Nginx以使用外部DNS服务器8.8.8.8进行域名解析,并通过/etc/hosts文件配置内部域名映射。同时介绍了安装和配置dnsmasq作为本地DNS服务的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx and DNS

On ubuntu-12.04, I need to run this
> sudo dpkg-reconfigure resolvconf

To solve the Error
resolvconf: Error: /etc/resolv.conf isn't a symlink, not doing anything

First of all, let me describe the issue.

I plan to use Nginx to proxy external domain which need 8.8.8.8 to resolve the DNS. Depend on the header value, the request main proxy to and internal IP which the domain name and IP configuration is configured in /etc/hosts.

Install the DNS service on Local
> sudo apt-get install dnsmasq

Start running the service
> sudo service dnsmasq start

The NGINX configuration will be similar to this:
map $http_user_agent $target {
default 'https://ocp.sillycatcloudbeta.com/SillycatServer';
"oldclientsproxy" 'http://local-hosts-external-ip:5080/SillycatServer';
"test" 'http://requestbin.fullcontact.com/1fio7ty1/SillycatServer';
}

location /SillycatServer/useragentapi {
resolver 127.0.0.1;
proxy_pass $target/useragentapi$is_args$args;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ssl_server_name on;
}
location /SillycatServer/provisioning {
resolver 127.0.0.1;
proxy_pass $target/provisioning$is_args$args;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ssl_server_name on;
}


Then the resolver will first look up /etc/hosts and then it will working similar as 8.8.8.8 to look up AMAZON AWS domain.


References:
https://github.com/arrivu/beacon/wiki/Solution-for--------resolvconf:-Error:--etc-resolv.conf-isn't-a-symlink,-not-doing-anything
https://askubuntu.com/questions/54888/resolvconf-u-gives-the-error-resolvconf-error-etc-resolv-conf-must-be-a-sym
http://www.enkichen.com/2017/05/23/dnsmasq-introduce/
https://stackoverflow.com/questions/8305015/when-using-proxy-pass-can-etc-hosts-be-used-to-resolve-domain-names-instead-of/8559797#8559797
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值