G
G
grechinaoleg2015-10-15 21:35:27
Nginx
grechinaoleg, 2015-10-15 21:35:27

How to handle non-existent domains in nginx?

Good day to all!
I spent a long time digging with the transfer of my Joomla from Apache to the nginx PHP-FPM server, in the end I did everything I wanted, but there was such a problem: The
site began to open by IP, googled and found this code

server {
    listen 80;
    server_name xx.xxx.xxx.xx;

    rewrite  ^/(.*)$  http://site.ru/$1 permanent;
}

As a result, a redirect to the domain appeared, which, in principle, suited me.
Then I go to Adsense and see income from a domain unknown to me, go to this domain, and my site opens there. I looked at Whois, and my IP is registered at the domain, and as a result, nginx quietly gives the entire site to the left domain.
Tell me what to do to open exactly my site by site.ru domain, by ip and left domains so that it gives 403 or something like that.
The server has ISPManager 5 Lite (Domain added from the panel)
The main Nginx config looks like this (/ etc/nginx/nginx.conf):
user www-data;
worker_processes 8;
pid /run/nginx.pid;

events {
  worker_connections 1024;
  multi_accept on;
}
http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  gzip on;
  gzip_disable "msie6";
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
  include /etc/nginx/vhosts/*/*;
  server {
  server_name localhost;
  disable_symlinks if_not_owner;
  listen xx.xxx.xxx.xx:80 default;
  include /etc/nginx/vhosts-includes/*.conf;
  location @fallback {
    error_log /dev/null crit;
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect http://127.0.0.1:8080 /;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    access_log off ;
  }
  }
}

And this is how the config for the main site looks like (/etc/nginx/vhosts/webkilla/site.ru.conf):
server {
  charset off;
  disable_symlinks if_not_owner from=$root_path;
  index index.html index.php;
  root $root_path;
  set $root_path /var/www/webkilla/data/www/site.ru;
  access_log /var/www/httpd-logs/site.ru.access.log ;
  error_log /var/www/httpd-logs/site.ru.error.log notice;
  listen xx.xxx.xxx.xx:80 default;
  server_name site.ru www.site.ru;
  include /etc/nginx/vhosts-includes/*.conf;

  location /administrator/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/.htpasswd;
  }
  location / {
    expires 1d;

     # Enable joomla SEF URL's inside Nginx
     try_files $uri $uri/ /index.php?$args;
    
  }
  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]";
    fastcgi_pass unix:/var/www/php-fpm/webkilla.sock;
    fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    try_files $uri =404;
    include fastcgi_params;
  }
  ssi on;
}

Please, tell me what to do so that non-existent domains / subdomains or when opening by ip give an error and preferably a file in which to enter it?
ps My first server on nginx, I don't understand a lot, so I can't correctly compose queries for Google
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2015-10-15
@grechinaoleg

Create a new virtual host (server section) and write to it
And also read how nginx handles requests .
Please note that there can be only one virtual host with the default_server directive.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question