Reputation: 26161
For development, I'd like to serve multiple projects on different local domains, all on port 80. In my hosts file I direct local.example.com to localhost, same for local.example2.com.
Now I'm trying to convince nginx to serve the example resources for the one url, and the example2 resources for the other.
I've read the nginx documentation and this blog post. But I think I must be missing something.
I've added to my nginx.conf:
include /Users/iwein/Sites/conf/*.conf;
Then in sites I add configuration like example.conf
:
server {
listen 80;
server_name local.example.com;
…
and example2.conf
:
server {
listen 80;
server_name local.example2.com;
…
Now the weird thing is that nginx seems to load the alphabetically first config, but on the second url, it serves the resources from the first server definition too. Nginx seems to totally ignore the server_name. How should I configure for this use case?
UPDATE:
It appears that if you use only one separator in the domain name (e.g. example1.local), it works just fine. I didn't further pursue this, because I have better things to do, but it's odd.
Upvotes: 19
Views: 17487
Reputation: 26161
Apparently, nginx doesn't like the format of my server names. If I remove the 'local' subdomain it seems to work much better. I'm now working with example.dev
and example2.dev
and the problem is gone.
Upvotes: 5