Serving two sites from one server with Nginx
The default_server parameter, if present, will cause the server to become the default server for the specified address:port pair.
It's also obvious, there can be only one default server.
And it is also says:
A listen directive can have several additional parameters specific to socket-related system calls. They can be specified in any listen directive, but only once for the given address:port pair.
So, you should remove default
and deferred
from one of the listen 80
directives. And same applies to ipv6only=on
directive as well.
Just hit this same issue, but the duplicate default_server
directive was not the only cause of this message.
You can only use the backlog
parameter on one of the server_name
directives.
Example
site 1:
server { listen 80 default_server backlog=2048; server_name www.example.com; location / { proxy_pass http://www_server; }
site 2:
server { listen 80; ## NOT NOT DUPLICATE THESE SETTINGS 'default_server backlog=2048;' server_name blogs.example.com; location / { proxy_pass http://blog_server; }
I was having the same issue. I fixed it by modifying my /etc/nginx/sites-available/example2.com file. I changed the server block to
server { listen 443 ssl; # modified: was listen 80; listen [::]:443; #modified: was listen [::]:80; . . .}
And in /etc/nginx/sites-available/example1.com I commented out listen 80
and listen [::]:80
because the server block had already been configured for 443.