By benborgers
I want to offer support for custom domains for my users. I created a file in /etc/nginx/sites-avilable/ with a server block that routes everything to an Express app (running with PM2). I want to use Express to get the domain they are requesting from, cross reference that domain name, and show the appropriate user’s page. However, something like req.headers.host only gives me ‘localhost:3000’. How can I get the domain name of the request? Or is there a simpler way of doing 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!
Hello friend!
I confess that I do not know off the top of my head the absolute correct path, but I wanted to weigh in because I might be able to help you move in the direction of finding it. It makes sense that you see that when using Nginx as a reverse proxy. If your app took the requests directly, acting as it’s own web server, that would resolve it. However, Nginx is going to be better optimized in most cases. So what you’re looking to do is forward the request URL as another variable to the app, and then have the app pull that variable. I believe that this will take you in the right direction:
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Kind Regards, Jarland
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.