💾 Archived View for gmi.bacardi55.io › blog › 2016 › 12 › 07 › adding-a-default-vhost-to-nginx captured on 2024-08-24 at 23:50:39. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
Posted on 2016-12-07
Today I wanted to install this blog on my new nginx[1] server. As this site is simply static html file, I thought why not using it as well to try to learn how to use it.
So I created my server :
{% raw %} server { listen *:80; server_name bacardi55.org; root /var/www/b-55-log/web; access_log /var/log/nginx/blog_access.log; error_log /var/log/nginx/blog_error.log; } {% endraw %}
Then, I wanted to add two other domain to redirect to this one:
{% raw %} server { listen *:80; server_name domaine2.tld domaine3.tld; access_log /var/log/nginx/other_domaine.access.log; rewrite ^ http://bacardi55.org permanent; } {% endraw %}
But It didn't work as I didn't have a default server. The redirection wasn't working as nginx considered my blog server the default. So the to 2 other vhost kept working and wasn't redirected. I didn't like that because I don't want this blog to be indexed 3 times by search engines.
So to correct this, I had to create a default server that redirect everything that didn't match any of my other server_name. This is what I put in my conf file:
{% raw %} server { listen *:80 default; server_name _; access_log /var/log/nginx/default.access.log; server_name_in_redirect off; root /var/www/; } {% endraw %}
Be careful though, I followed the documentation and put
listen 80 default;
And there you go :)
But it didn't work. I actually had to put the IP:80 instead of just 80 as in the official doc.
I may have miss something in my nginx that make it doesn't work but if than can help someone other than me :).
PS: Thanks to my friend Rustx[2] to advising me not to use the IP address but only *:80.