Nginx always redirecting http to https - redirect

Hiyas, Im trying to redirect my non-www domain to a digitalocean droplet serving localhost:3000. When I type in my http://non-www domain, I get a 302 redirect to the https version of the non-www domain.
Here's the pastebin to my config stuff - http://pastebin.com/89HP07cW
I also added A record to digitalocean domain, to point to ip. And 2 cnames, * points to #, and www points to #. I'm just hacking now, reading through all the solutions and config file seems straight forward, but not working for me.

Related

Static webpage redirect http to https using Google loadbalancer

I'm trying to implement URL redirects from http to https as described by [https://cloud.google.com/load-balancing/docs/https/setting-up-traffic-management][1] but I'm getting ERR_TOO_MANY_REDIRECTS
I have a storage bucket with a very simple HTML page.
I have an external HTTP load balancer in front of it. Static IP address. SSL cert. I managed to connect everything so that both http and https requests for the site load the contents of the bucket.
I tried to add the HTTP redirect as per the document:
Changes 'Host and path rules' from 'Simple' to 'Advanced...'.
The default route still points to the bucket
I added a new route. Host is 'www.example.com. The default path rule points to the bucket. The second path rule matches /* and does a prefix/HTTPS redirect as described in the above link.
Once the config is saved, either http or https requests to www.example.com results in ERR_TOO_MANY_REDIRECTS
What am I doing wrong? Really appreciate any help you can provide.
[Backend configuration][2]
[Frontend configuration][3]
[Host and path rules][4]
[Redirect path rule][5]
[1]: https://cloud.google.com/load-balancing/docs/https/setting-up-traffic-management
[2]: https://i.stack.imgur.com/lkhUF.png
[3]: https://i.stack.imgur.com/FYst0.png
[4]: https://i.stack.imgur.com/zsTOX.png
[5]: https://i.stack.imgur.com/2tEDE.png
FYI - someone in Google Groups pointed out that I needed 2 load balancers. 1 to terminate the HTTPS traffic and the second to redirect the HTTP traffic. Works like a charm.

CloudFront double redirect my naked domain

I followed the accepted answer here:
Cloudfront redirect www to naked domain with ssl
Here is what I did:
Create two S3 buckets named: example.com and www.example.com.
2.Turn on the Static Website Hosting on these two buckets.
3.Configure redirect in bucket www.example.com to bucket www.example.com. Protocol I chose https
4.For these buckets create two CloudFront Distributions. Each of this distributions point to corresponding bucket:
For Origin Domain Name provide bucket urls provided in Static Website Hosting section. The urls should have form (or similar): example.com.s3-website-us-west-1.amazonaws.com
On both distribution set HTTP to HTTPS redirect.
Route 53 configure DNS by setting:
An Aias records for example.com to point to corresponding CloudFront distribution.
An CNAME for www.xample.com to point to corresponding CloudFront distribution
The result:
http://www.example.com gets redirected to https://example.com
https://www.example.com gets redirected to https://example.com
This is the strange one:
When I enter example.com directly on my browser, I noticed that it gets redirected very quickly to http://www.example.com or (or https://www.example.com, it's too fast, I can't see it well), then immediately gets redirected to https://example.com.
Why there is a double direction here?
thx.

Https redirect from DNS Host?

So I'm trying to figure out if this is something I can configure through my DNS host or if I need to set this up on my app server.
My situation
I have a heroku app and domain name (lets say example.com) which is set up for https on both www and root/apex. So https://example.com and https://www.example.com both work. I am also able to redirect any http requests (both www or root/apex) to domain to the https equivalent so in other words:
http://www. redirects to https://www. and http://root redirect to https://root.
My issue
I want all combinations of my urls (http or https and www or root) to direct to a single url (https://www or https://root). My aim is to just have consistency in the urls. I noticed that most redirects work EXCEPT when trying to redirect from https://example.com to anything else.
What is the DNS host approach for this? And if it's not possible from DNS host the normal approach?
DNS provides translation from the domain name in a URL to an IP address that the client can contact. If your problem involves anything else whatsoever in the URL, it's not a problem DNS can solve.
The problem you describe involves the difference between HTTP and HTTPS. This is not part of the domain name in the URL. Therefore, DNS is not your problem.

AWS Route 53 CNAME

This has to be simple. I have an A record that points to my server just fine. However, I just added a CNAME for a "www".website.com that points to website.com, but it is now just returning an Nginx 404 error. For reference, I'm using Laravel Forge to deploy the server and of course AWS Route 53 for DNS.
I want to post an answer in case anyone comes across this issue like I did. I was unaware that this can be solved by configuring the Nginx config file and through Laravel Forge, it's pretty easy.
On my server, I have 2 sites (one pointing to site.com and one pointing to www.site.com). In my DNS provider (AWS Route 53), I have an A record for each URL and both point to the public IP of my server.
So, I go into the Nginx config (through Laravel Forge) for the site I want to redirect (in this case I want to go from www to non-www) and edit the config file to include the following.
server_name www.site.com;
return 301 $scheme://site.com$request_uri;
Works perfectly now!

Redirect non www requests without redirecting sub-domains

To replace a legacy web site, a client has pointed their DNS at my server where a new version of the website exists.
However they still serve http://support.example.com from their own server.
I have noticed that non-www requests, e.g. http://example.com still point to their own server, therefore show the old web site.
How can I point non-www requests, http://example.com at my server without breaking the functionality of their 'support' sub-domain?
The client's server is a Microsoft server, mine is Linux/Apache
Edit: Changing the DNS 'A' record will not break the existing sub-domain
I know I could add an index.html page to the front of the old site, but if it was ever deleted the page requests would cease to work
I can't use mod-rewrite because I don't have access to their web server files
PROPOSED SOLUTION:
On the client DNS, create an A
record for:
support.example.com – IP of the client's server
example.com – IP of my server
www.example.com - IP of my server
No need for any DNS changes on my server regarding this domain
Changing the A record for example.com won't affect the A record for support.example.com.