Reputation: 25
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;
} ```
Upvotes: 0
Views: 320