Question

Can we host multiple websites in nginx at localhost?

I have a general question about nginx

Let say you don’t have a domain first, but you already fired up your droplets. You already success setup Nginx in your droplet.

But your plan is to host 2 website in the droplet So the first website is done, assuming the default nginx page is the first website.

Now, how can i host the second website? Remember for now i still dont have the domains. What to put in the nginx configuration (server_name) for the second website?

For the first website, i already use “server_name localhost;”

What sould i put for the second website?


Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I prefer creating separate virtualhosts for each app and setting server_name to app_name.dev; <br> <br>Edit your /etc/hosts file and add the following line: <br>127.0.0.1 app1.dev app2.dev etc.dev; <br> <br>You should be able to access your apps by browsing to http://app_name.dev

@Dzulhelmi: Create a second virtualhost for the second app/website, and set its server_name to e.g. app1.dev: <br> <br>https://www.digitalocean.com/community/articles/how-to-set-up-nginx-virtual-hosts-server-blocks-on-ubuntu-12-04-lts--3

Kamal, <br> <br>I dont get it. Let say currently my localhost already have one website. Which is can be opened by http://localhost <br> <br>And right now i want to add one more website since nginx can serve more than one website, ok let say i edit my hosts file like what you wrote there. <br> <br>Now in my nginx configuration for this second website, what should i put for the server_name? <br>Since the localhost is already pointing the default first website?