0

I am getting used to the nginx web server app. I have always had problems setting up the different server_name in the nginx conf file usually situated on /etc/nginx/sites-enabled/

What I did is I have setup up the server so it can display more then 1 web server at a time. I currently have default and thecanadiansos config file.

If the user enters : thecanadianssos.com in the browser, it says it can't reach the server ip. If the user enters : w.thecanadiansos.com in the browser, it goes to the default nginx page.

The user must write : www.thecanadiansos.com in the browser for it to works. ( the https seems to work well)

How must I setup my thecanadiansos nginx config file to fix everything? The systax is ok and the site is working but the file might have mistakes I tried many solution and couldn't find the issue alone. Here is what I currently have hope you can help, thank you :)

server {
    server_name thecanadianasos.com www.thecanadiansos.com;
    root /var/www/thecanadiansos;

    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
     }

    location ~ /\.ht {
        deny all;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.thecanadiansos.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.thecanadiansos.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}

server {

 if ($host = www.thecanadiansos.com) {
return 301 https://$host$request_uri;
}

    listen 80;
    server_name thecanadiansos.com www.thecanadiansos.com;
    return 301 https://www.thecanadiansos.com$request_uri;
} ```

sin0c
  • 25
  • 4
  • 2
    You have a typo error `server_name thecanadianasos.com ...` in your config. The `thecanadianssos.com` in your question isn't your domain too. `w.thecanadiansos.com` isn't listed in your server names. – Ivan Shatsky Nov 06 '20 at 14:17
  • Thanks, I was able to get the w. to work. Only thing is if there is no w. it doesnt find the ip, not sure if it is a big deal? – sin0c Nov 06 '20 at 17:24
  • 1
    Check `nslookup thecanadiansos.com` and `nslookup www.thecanadiansos.com`, do these commands return the same address? – Ivan Shatsky Nov 06 '20 at 18:07
  • Thank you for you time, I just tried that. `Server: node-1w7jr9n24twqzs2cg5ed4tjkj.ipv6.telus.net Address: 2001:568:ff09:10c::53 Name : thecanadiansos.com` The second one : `Server: node-1w7jr9n24twqzs2cg5ed4tjkj.ipv6.telus.net Address: 2001:568:ff09:10c::53 Non-authoritative answer: Name: www.thecanadiansos.com Address: 188.166.54.129` Thank you for the help, I think you are in the good direction. The IP dns doesnt seem to be setup for none www server name – sin0c Nov 07 '20 at 09:10
  • 1
    That means you should setup your DNS correctly. How to do it depends on your registrar (usually via some kind of a web interface) and definitely is an offtopic at StackOverflow site. – Ivan Shatsky Nov 07 '20 at 18:07

0 Answers0