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 do this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
You can forward your request to Node.js app by using proxy_pass directive.
Look at your mydomain.com server block.
It is usually in /etc/nginx/sites-available/default if you didn’t changed default settings. You can make it like this:
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
...
server_name mydomain.com www.mydomain.com;
location / {
return 301 https://mydomain.com/resume$request_uri;
}
location /resume {
proxy_pass http://localhost:3000/;
}
...
}
This will ensure that your traffic to mydomain.com and mydomain.com/resume will get redirected to Node.js app. About redirection, just create a server block that will listen on resume.mydomain.com and redirect to mydomain.com/resume.
server {
listen 80;
listen [::]:80;
server_name resume.mydomain.com
return 301 https://mydomain.com/resume$request_uri;
}
This will listen only for http traffic. If you used https on resume.mydomain.com, you should still make it listen on 443 with cert, so it doesn’t report Server not found error if accessed via https. This should do its job, I hope it isn’t a lot late.
After you done with changes, test your nginx with
- sudo nginx -t
If everything goes well just restart it:
- sudo systemctl restart nginx
Try and observe results, if it is not working correctly, we will make it :D Edit: added more informations.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.