Move resource with Nginx rewrite/redirect - node.js

I have a node app running on http://localhost:3000. I set up ssl/https with LetsEncrypt so all requests are 301 redirected to https. Im using Nginx as web server.
I'm trying to move my URL from resume.mydomain.com to mydomain.com/resume.
How do I forward requests to mydomain.com AND mydomain.com/resume to my node app?
If users go to mydomain.com AND resume.mydomain.com they should automatically be redirected to mydomain.com/resume.
How do I do this?

Related

Adding Fastly to a Heroku app does not forward to proper url

I currently have an Heroku app that is being served over a CDN. I have just added Fastly to my Heroku app as an addon and I am struggling to configure it properly. Here is my current configuration:
I have my domain registered on GoDaddy with the following CNAME configuration:
Host: www
Points to: my-site-herokuapp-com.global.ssl.fastly.net
TTL: Custom
Seconds: 600
Here is the GoDaddy forwarding configuration (not sure if this matters):
Forward to https://www.my-site.io/
(301 & forward only)
Here is my fastly configuration:
Domains:
my-site-herokuapp-com.global.ssl.fastly.net
*Provisioned for my-site via Heroku*
my-site.herokuapp.com
*Provisioned for my-site via Heroku*
www.my-site.io
And finally in Heroku in the domains configuration section of my app here are my settings:
Domain Name: my-site.io
DNS target: darwinian-kumquat-123456.herokudns.com
Domain Name: www.my-site.io
DNS target: serene-trout-123456.herokudns.com
Before I tried to make this change I had the CNAME pointing directly to: serene-trout-123456.herokudns.com an it was working fine. However after updating this value to the new Fastly value: my-site-herokuapp-com.global.ssl.fastly.net Fastly directs the site to my-site.herokuapp.com instead of just https://www.my-site.io. I followed the instructions listed here so not entirely sure where I have gone wrong. Any ideas?
Probably because you used redirect 301 and you are using the same browser as before before cleaning cache and data.
301 redirects are recomended only for very limited cases: once done the browsers will NOT refresh again any data from the original server.
There are plenty of posts regarding redirection 301, for example:
Cannot remove 301 redirect
htaccess 301 redirect - how to disable it?
https://www.exai.com/blog/301-redirects

nodejs - session lost while switching from www to non-www

(New to web development)
I'm using nginx for my nodejs website on a Digital Ocean instance.
I'm using passport.jsfor facebook login on http://www.example.org/login. My callback URL is http://www.example.org/auth/facebook/callback.
The session works if I access the website using http://www.... but it gets lost if I switch from http://www to http://
I've already tried creating a redirect in /etc/nginx/sites-available/default using:
server_name example.org
rewrite ^/(.*)$ http://www.example.org/$1 permanent;
but this isn't working. What am I doing wrong?
Can anybody help me with setting the session for both www and non-www versions of my domain in nodejs, or correctly writing the redirect?

Different ways to do a redirect

I'm working on an old website and I've just found something strange. Www.mysite.com redirects to www.test.com, while mysite.com (non-www) redirects to www.other-site.com.
I've checked the htacces, and it only contains rules to redirect traffic to test.com. www.other-site.com is not present in the file. So how is it possible? Where should I check if there's a rule for this redirect?
Environment:
Centos server /
Apache /
Three sites are on different servers
This could be a DNS issue. If both www.test.com and test.com point to the same server then it is all server side. Virtual hosts can sometimes be the problem if you have Apache set that way then you will need a Virtual host for both www.test.com and test.com. I would say start with the DNS, then the apache config, then the site folder.
Hope that helps.

Nodejs redirect url to tomcat server

To solve CORS issue, I need remove my server port and use apache to redirect to my tomcat with port.
example: http get url: localhost/app1/somerequest, my apache server will redirect to localhost:8080/app1/somerequest, so how can this redirect be work when i use nodejs?
If you want to proxy the request, use node-http-proxy.
If you want to redirect the request, see this

Using Passport-google behind proxy

I'm using Passport-google to login users in example.com:3000. It works great. But if I put the Node.js server behind a proxy (IIS7; don't ask why, I had to), and access to my site in example.com (not in example.com:3000), I can't login with Passport-google. My RewriteRule in IIS:
Pattern (.*)
{HTTP_HOST} Matches myserver.com
{SERVER_PORT} Does not match 3000
Rewrite URL: http://127.0.0.1:3000/{R:1}
The error I got:
Cannot GET /accounts/o8/ud?
Also I have the same problem with Passport-twitter, and Passport-facebook.
I think I should set some other rule in IIS, or set some proxy settings in Passport.js, or OpenID, but haven't figured out yet. Any ideas?
The IIS proxy had a bad configuration. under Application Request Routing (ARR) / Server proxy settings Reverse rewrite host in response headers was switched on, so when passport sent a 302 with a location in header set to https://www.google.com/accounts/o8/... the IIS proxy replaced it to http://myserver.com/accounts/o8/... . which of course was an invalid link.

Resources