Kohjah Breese
Kohjah Breese

Reputation: 4136

nginx host default for IP

I have the following default configuration file in nginx:

server {
listen 80;

root /home/d/www;
index index.php index.html index.htm;

server_name localhost;

Recently I added a file to host a specific domain, like:

server {
listen   80;
root /home/d/sites/dom
index index.html index.htm;

server_name dom.co www.dom.co;

After adding this, when loading the public server IP would be routed to this domain configuration folder, /home/d/sites/dom

How can the IP be directed to the default root?

Upvotes: 1

Views: 583

Answers (2)

Kohjah Breese
Kohjah Breese

Reputation: 4136

To add to Vasfed's answer, my block are:

/etc/nginx/sites-available/yourdomain

server {
listen   80;

root /www/sites/**yourdomain**;
index index.html index.htm;

server_name **yourdomain**.com www.**yourdomain**.com;
}

/etc/nginx/sites-available/default

server {
listen 80 default_server;

root /www;
index index.php index.html index.htm;

server_name _;
}
  • These two files need to by sym-linked to sites-enabled.

Upvotes: 0

Vasfed
Vasfed

Reputation: 18454

There's listen 80 default; for requests without Host header (if none set - the first one is used)

For requests with unrecognized host - special server_name _; matches

Upvotes: 2

Related Questions