How to Set Up Demo and Production Versions on Nginx?

0
17
Asked By UserNinja123 On

Hey everyone! I'm trying to figure out how to set up both a demo version and a production version of my website on the same server using Nginx. I want the production version to be available at the root ("/") and the demo version to be at the "/demo" path. I've shared my current Nginx configuration below, but I'm running into issues with the demo setup not working properly. The production site appears to serve just fine, but the demo does not seem to be accessible even though all the files are in place. I'm running this Nginx setup inside Docker at the moment. Is there any way to achieve this without needing a separate domain? Or am I potentially missing something in my configuration? Any help would be greatly appreciated!

3 Answers

Answered By CodeMasterX On

If you're planning to keep both versions on the same server, consider setting them up on separate subdomains instead. For your demo, you'd create a `CNAME` record in your DNS for something like `test.example.com`, and then add a new server block in your Nginx config specifically for that subdomain. Your Nginx config would then look something like this for the demo and main production site. It should help separate them cleanly!

UserNinja123 -

Thanks a lot for the detailed response! I’ll follow the subdomain approach and adjust my config. Appreciate it!

Answered By TechieTina On

It looks like your issue might stem from the way you've configured the root path in your demo location. Make sure that the trailing slash is intentional in your root path for the demo. Also, using a separate subdomain like 'demo.yourdomain.com' could be a better approach, as it allows the app to handle different URL roots more smoothly. That way, you'll avoid potential conflicts through the paths. It's also worth checking your DNS settings to make sure that's set up correctly!

DevDude42 -

I agree that a sub-domain is often better! It keeps the main site and demo more organized.

UserNinja123 -

I tried it without the slash and still had issues. I’ll definitely look into the subdomain option more. Thanks for the suggestion!

Answered By FrontendFanatic On

Can you clarify what exactly isn’t working with the demo version? Is your site built to function under a subpath? What tech stack are you using?

UserNinja123 -

My setup is using Vite and React, but the demo path redirects back to the main location, which results in a 404 error instead of showing the demo page.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.