NGINX Redirect to Domain Name spoofed locally with DNSMasq
0
votes
3
answers
3415
views
I have a Linux VPS serving data on the internet that has a legitimate Domain name and SSL Certificate ( from GoDaddy.com ). I will refere to this server as "**www.myserver.com**". I also have a local Linux machine ( on my own LAN ) that I want to use to DNS spoof my internet facing Domain name ( www.myserver.com ) to it's own NGINX webserver running on that local machine.
I setup DNSMasq on the local machine to spoof that domain to it's local 192.x address and I verified from another machine on the LAN that dig reports the local address.
Local server dnsmaq spoof mapping:
cat /etc/dnsmasq.d/spoof.hosts
192.168.1.142 www.myserver.com myserver.com
Separate machine on LAN shows that spoofed mapping should work:
dig +short @192.168.1.142 myserver.com
>> 192.168.1.142
My dnsmasq.conf:
server=127.0.0.1
listen-address=127.0.0.1
listen-address=192.168.1.142
no-dhcp-interface=
no-hosts
addn-hosts=/etc/dnsmasq.d/spoof.hosts
My spoof.hosts:
192.168.1.142 www.myserver.com myserver.com
On the local server, I configured NGINX with resolver to look to localhost for DNS as shown here:
http {
access_log off;
include mime.types;
default_type html;
sendfile on;
keepalive_requests 50;
keepalive_timeout 75s;
reset_timedout_connection on;
server_tokens off;
server {
listen 8080 default_server;
resolver 127.0.0.1 valid=10s;
location / {
return 302 http://myserver.com/ ;
}
}
server {
listen 80;
server_name *.myserver.com;
// Various Endpoints
}
}
The problem is that when I visit my local machine 192.168.1.131:8080, it redirects to my **actual** internet facing machine - the **real** domain name on the internet.
I want it to redirect to the local spoofed DNS. What am I doing wrong? How can I accomplish this? Thank you.
UPDATE: I've tried this as well but no luck:
http {
access_log off;
include mime.types;
default_type html;
sendfile on;
keepalive_requests 50;
keepalive_timeout 75s;
reset_timedout_connection on;
server_tokens off;
server {
listen 80 default_server;
server_name _;
resolver 127.0.0.1;
return 301 https://myserver.com/$request_uri ;
}
server {
listen 443;
server_name *.myserver.com;
ssl on;
ssl_certificate /etc/nginx/ssl/1e17e6d8f94cc4ee.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
...
}
}
Asked by PhilBot
(101 rep)
Feb 1, 2018, 01:34 PM
Last activity: Feb 12, 2018, 11:08 AM
Last activity: Feb 12, 2018, 11:08 AM