server_name
is space-separated, not comma-separated. It should be server_name example.com *.example.com;
.
Nginx server name without www pointing to wrong virtual host
-
28-09-2022 - |
Question
I have a Rails app and a Ghost blog installed on my server with Nginx as the web server. I want blog.example.com to point to my blog and everything else to point to main App.
My nginx.conf looks like this:
server {
listen 80;
server_name blog.example.com;
root /root/ghost;
location / {
...blah
}
}
server {
listen 80;
server_name example.com, *.example.com;
root /home/example/current/public/;
gzip_static on;
location / {
...blah
}
}
However if I omit the www in the domain, it goes to the blog instead of app. What am I doing wrong?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow