Wilcard domain with DigitalOcean and Nginx to catch all requests to subdomains - nginx

I have a large list of subdomains and the list continues to grow.
I recently started using Digital Ocean and I need to recreate the list of subdomains but the process of creating them one by one using the DNS Server control panel is very time consuming and besides that, whenever I need to create a new subdomain I will have to do it manually.
I'm trying to create a wildcard domain so that all subdomains are captured by the DNS server and then each one is redirected to the specific service.
The service that will be used is Odoo and it will work together with Nginx.
What I've done so far:
I registered the new domain name (example.com);
Updated the Domain Name Servers to point to Digital Ocean (ns1.digitalocean.com, ns2.digitalocean.com, ns3.digitalocean.com);
In the DNS control panel at Digital Ocean, I created the following DNS records:
A *.example.com xxx.xxx.xxx.xxx 3600
CNAME www.example.com example.com 43200
A example.com xxx.xxx.xxx.xxx 3600
NS example.com ns1.digitalocean.com 1800
NS example.com ns2.digitalocean.com 1800
NS example.com ns3.digitalocean.com 1800
For the records "example.com" and "www.example.com" everything seems to be working because when I ping I see that the traffic is redirected to the Digital Ocean droplet.
In Nginx I created a server block and included as servers:
server {
...
server_name example.com www.example.com *.example.com .example.com test.example.com;
...
}
With this configuration I can easily access the Odoo server using the addresses: example.com and www.example.com but when I try to access the address "test.example.com" I cannot access the server.
Surely it will be necessary to perform some more step that passed me and I didn't find in my searches?

I found that during the tests I had placed a record in the /etc/hosts file with:
127.0.0.1 test.example.com
After removing this record, everything is working as expected.

Related

Problem redirecting subdomain to nginx web server

Problem explanation
I want to show one service in my domain and another different service in my subdomain, so I purchased a domain and tried to link it to my Nginx web server.
I have buyed the domain in google domains. And uploaded my web application to a Nginx web server.
When I run my domain for example www.balls.com it's redirected perfectly, but when I try to redirect to my subdomain, there is no way to make it work, I have tried different configurations and received 2 different errors:
-DNS doesn't exist (Checked with DNScheck).
-Google DNS page error.
google domain service config:
Nameservers:
-Using the Google Domains nameservers.
DNSSEC
-Your domain has DNSSEC enabled.
Registered hosts
red.balls.com-->111.11.11.11 (My server Address).
Synthetic records
Domain forward
balls.com, www.balls.com → 111.11.11.11 (My server Address).
Custom resource records (Extracted from exported records)
balls.com.balls.com. 3600 IN A 111.11.11.11
red.balls.com.balls.com. 3600 IN A 111.11.11.11
www.balls.com. 3600 IN A 111.11.11.11
www.balls.com.balls.com. 3600 IN A 111.11.11.11
nginx services config:
Subdomain service:
server {
listen 80;
root /var/www/redballs.com;
index index.html index.htm;
server_name red.balls.com;
}
Subdomain service:
server {
listen 80;
root /var/www/balls.com;
index index.html index.htm;
server_name balls.com;
}
Thanks for your read time, a simple comment pointing what I'm doing wrong will be very appreciated, as I have finished my application but I'm unable to set up this subdomain. Thanks again.
that sounds a lot like a DNS problem to me.
Did you add a DNS record for the subdomain?
Each hostname you want to use needs a mapping in DNS to the IP addresses of the host or a CNAME pointing to another name.
It is a bit hard to debug a DNS Problem without seeing thr actual data.
Sidenote: www.balls.com.balls.com. looks to me like you forgot a dot when creating that entry. In DNS a name always ends with a dot in the configuration (or zone file) if you omit it, the domain name is usually automatically appended.

Nginx uWSGI link server_name to domain for flask application

I have written a Flask website which I hosted with waitress on a Ubuntu 20.04 VM server at port 5000, but now I'd like to do it more properly with uWSGI/Nginx.
To learn uWSGI/Nginx I am following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-20-04
Here in step 6 it tells my to configure Nginx as follows:
server {
listen 80;
server_name my_domain www.my_domain;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/sammy/myproject/myproject.sock;
}
}
However if I now request the webpage for my domain, it only returns the default Nginx page.
But if I "hardcode" the public IP address of my server to the server_name:
server_name: my_domain www.my_domain MY_IP
Then it does show the correct page. I however have a feeling this is not the intended way to configure the server.
When I used the old waitress server i had told my DNS server redirect to http://MY_IP:5000/, but it is now set to redirect to http://MY_IP/. (with redirect mode 302)
So my question is, how should I set up my Domain name redirect or Nginx config so that it works without a "hardcoded" ip? Or is this something where I just need to wait the 48 hours for the DNS update to propagate?
Also an auxiliary related question, how do I make the browser url bar show the domain name instead of an IP address?
Thanks in advance!
You can go through my answer, hope it helps you as well
Regarding your question for URL name in browser, it will be there once DNS name is propagating properly and it shouldn't take more than 5-10 minutes.
Remove the IP from server name, its not supposed to be entered there.

Can't properly forward GoDaddy domain to Heroku server via HTTPS

I have a problem with configuring Godaddy DNS and Heroku hosting server.
The goal is: when I type www.example.com or example.com as URL, it needs to go https://www.example.com.
Right now when I go www.example.com or example.com, it goes http://www.example.com
Configurations are:
On Heroku
heroku domains:add www.example.com (SSL is working. Cert issued)
On GoDaddy
DNS record: type=CNAME name=www value=www.example.com.herokudns.com
DNS forwarding domain: forwardto=https://www.example.com forwardtype=Permanent(301) settings=Forwardonly
DNS forwarding subdomain: subdomain=example.com forwardto=https://www.example.com forwardtype=Permanent(301) settings=Forwardonly
P.S. If I manually go https://www.example.com the browser shows that it is secured
Edit: Update my nameservers and DNS settings to support this change is checked
Under GoDaddy doamin forwarding, make sure to check the box next to "Update my nameservers and DNS settings to support this change", then save.
If that is done. Confirm that your local dns cache has updated. Run these two commands, if the IP addresses returned are different, you may need to clear your cache or make sure that you haven't made manual changes to your host file.
nslookup example.com 8.8.8.8
ping example.com
Are you using Apache? If so, the .htaccess file is the best way to change the default domain.

Checking SSL works before migrating a site

I have a website on server 1 that has an SSL certificate, I need to move a new developed site to server 2 which has a new SSL certificate. The SSL has been installed on server 2, is there anyway to check if the site and the ssl certificate works before changing the nameservers from server 1 to server 2.
I have tried editing the hosts file on my computer with the IP address of server 2 and the site loads, but as it only shows the IP address in the url bar so there doesn't seem to be a way to tell if the SSL is working, if i add https:// to the domain IP it doesn't work.
Thanks in advance.
When you change the hostfile to the second server with the correct domainname it should listen as if it were used from a nameserver from the outside world.
For example, if you want to test server 2 with IP 194.194.194.194 with the domainname www.example.com you should add this line to your hostfile:
194.194.194.194 www.example.com
After you add this it is possible to go to https://www.example.com which should serve you the certificate if everything is configured right.
Cheers!

route 53 CNAME with Nginx

I have a domain and its DNS entries are managing using AWS Route53.
I have 30 servers on a datacenter which only have private IPs, and the sites hosted on these servers are loading using a nginx proxy server which have public IP.
For this, I have created an A record (say *.abc.com A IPofproxy), then I added some redirection rules on proxy server to load the corresponding sites.
redirection rule on proxy server are as follows :
1.abc.com redirects to 1.1.1.1
2.abc.com redirects to 2.2.2.2
3.abc.com redirects to 3.3.3.3 , etc.
But now am facing an issue with the CNAMEs,
The issue is,
I created some CNAME records like :
abc.abc.com CNAME 1.abc.com
def.abc.com CNAME 2.abc.com
fgh.abc.com CNAME 3.abc.com , etc
Then I tried to access all of the above domains (abc.abc.com , def.abc.com, etc), but all the sites are pointing to only one server which is the first one on redirection rules.
I am new to nginx, it would be great if anyone help me to fix this.
If I'm understanding your configuration correctly, the issue you're experiencing is not specifically related to either Route 53 or Nginx.
Instead, it's related to how web browsers interact with DNS entries. You'd have this issue with any reverse proxy server.
You have to configure each CNAME entry in your proxy, individually, because the browser doesn't care about the CNAME entry -- the Host: header sent with each request is the hostname the browser started with, not the hostname the browser ended up with after any CNAMEs were traversed.
a.example.com IN A 203.0.113.1
b.example.com IN CNAME a.example.com.
A request for b.example.com will be routed by the proxy according to its rules for b.example.com and not by its rules for a.example.com, because the CNAME does not change the browser's Host: header, which is what the proxy is almost certainly using for its routing decision.
If you want requests for b.example.com, it must be configured in the proxy, and not only in the DNS.

Resources