nginx設(shè)定server的時(shí)候 server_name為什麼不行
server {
listen 8000;
server_name kaixuan.test.com;
root /data1/htdocs/kaixuan.test.com/;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
location / {
index index.html;
}
}
server {
listen 80;
server_name kaixuan.hehe.com;
root /data1/htdocs/kaixuan.hehe.com/;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
location / {
index index.html;
}
}
上面是我的程式碼,我設(shè)定了兩個(gè)server,server_name 和連接埠是不一樣的
但是我造訪 kaixuan.hehe.com:8000 竟然也進(jìn)入了kaixuan.test.com。 【注意連接埠】
同樣,我造訪 kaixuan.test.com 也能進(jìn)入kaixuan.hehe.com,這正常嗎?
如果這樣正常的話,那我們?cè)诰€上怎麼解決?加一個(gè)預(yù)設(shè)的讓他預(yù)設(shè)進(jìn)去嗎?
對(duì)的,加上一條預(yù)設(shè)的阻擋。
當(dāng)所有server的規(guī)則都不符時(shí),nginx會(huì)採用第一條server配置,所以一般第一條server會(huì)使用阻止頁面。
server {
listen 80;
server_name _;
return 404;
}