我有两个域名: staging.abc.com和www.example.com指向我的DNS中相同的服务器IP。 我没有为staging.abc.com启用/可用的网站,但是我有一个用于www.example.com 。 但是,每当访问staging.abc.com ,它都指向www.example.com 。
这是我的conf 。 我的/etc/nginx/nginx.conf是默认的。 我没有改变任何东西。
我没有sites-available/default 。 它已被删除。
# sites-available/example server { listen 80; server_name example.com; return 301 http://www.example.com$request_uri; } server { listen 80; listen [::]:80; root /home/deployer/example; index index.php index.html index.htm; server_name www.example.com; location ~* .(jpg|jpeg|png|gif|ico|css|js|woff)$ { expires 30d; } location / { try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_read_timeout 300; } include /home/deployer/example/nginx.conf; } # nginx.conf user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## charset utf-8; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; proxy_read_timeout 300; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ...
我试图插入这个http块,但无济于事:
server { listen 80; server_name ""; return 444; }
这是我想要达到的:
除非你明确地定义了一个默认的服务器,否则Nginx会使用第一个服务器端口的匹配端口来处理没有server_name匹配的任何请求。 详情请参阅此文件 。
你应该创build一个捕获所有的服务器块,例如:
server { listen 80 default_server; return 444; }