By hrva07
What exactly is “server_name” in nginx configuration file ?
I’m trying to set up 2 websites with different domain names. I bought 2 domain names and pointed them to my droplet IP. I use Ubuntu droplet and nginx.
It works when I set only 1 website - then both domain names results by opening that website.
But later I tried to create 2 websites and set nginx to serve each website to its domain name. I get one of the two results: both domain names opens first website, or both domain names get ERR_CONNECTION_REFUSED.
I played around with the nginx configuration, looked at some tutorials here, but it doesn’t work for me.
So I want to go from start :-)
What exactly is “server_name” ? And what should it looks like ? Like domain name, folder name, configuration file name ?
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!
This question was answered by @olavamjelde:
Each server block in your /etc/nginx/sites-enabled/default will have a server_name.
Server name is what it will listen for, together with your port settings. So let’s say you have a domain, you point your A name like: example.com to your droplets IP. This lets the DNS server know where the domain should go (like a street adress).
Then you can set a server block inside the default file, with server name: example.com But you wish to also have this accessible via www.example.com, that mens you change it like so: server_name example.com www.example.com;
If you then want to have a subdomain like: yolo.example.com and have it work in another directory, you make another server block and you there add server name: yolo.example.com
You also have to add the a name in the DNS agian, point yolo.example.com to your ip. For maximum flexibility use: a name>floating ip>your server
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.