By PC000
Hello,
Warning - Complete newbie here.
I’ve followed the below guide “How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04” to set up my Django website.
Everything works fine when i search for my website via “website.com”, however when i search for “www.website.com” i get a welcome to nginx landing page.
I’ve attempted to fix this by adding the “www.” prefix version of my domain to the server_name line in my server block as per below.
server {
listen 80;
server_name website.com www.website.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/peter/websitedirectory;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
However when running sudo nginx - t on the above, i get a warning:
nginx: [warn] conflicting server name: “www.website.com” on 0.0.0.0:443, ignored
I’m not entirely sure what this means. I feel like this should be relatively simple to fix, can anyone help? Thanks!
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!
Your default file has server_name _; which will match any host (including what you’re seeing with www.website.com). Just disable the “default” file completely. Also change this line:
if ($host = website.com) {
To
if ($host ~ "website.com") {
And change this line:
server_name website.com;
To:
server_name website.com www.website;
Then restart Nginx.
What do you get when you search for www.website.com in the nginx directory?
grep “www.website.com” -r /etc/nginx
This comment has been deleted
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.