如何在Ubuntu上设置nginx虚拟主机
问题:不需要的nginx vhost重定向到www.domain.com如何在Ubuntu上设置nginx虚拟主机,nginx,dns,host,vhosts,Nginx,Dns,Host,Vhosts,问题:不需要的nginx vhost重定向到www.domain.com 我按如下方式配置了我的服务器/dns: root@letthemstare:~#cat/etc/hostname 让他们凝视 root@letthemstare:~# cat /etc/hosts 127.0.0.1 localhost 127.0.0.1 letthemstare.dev.local letthemstare #Virtual Hosts 178.62.111.20 letthemstare.
让他们凝视
root@letthemstare:~# cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 letthemstare.dev.local letthemstare
#Virtual Hosts
178.62.111.20 letthemstare.com
root@letthemstare:~# head -20 /etc/nginx/sites-available/letthemstare.com
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
listen 80;
server_name www.letthemstare.com letthemstare.com 178.62.111.20;
root /var/www/lts/public_html;
## rewrite example.com to www.example.com
if ($http_host != "letthemstare.com") {
rewrite ^ $scheme://letthemstare.com$request_uri permanent;
}
sudo ln-s/etc/nginx/sites available/letthemstare.com/etc/nginx/sites enabled/letthemstare.com
Kfirs-MacBook-Pro:~ silis$ ping letthemstare.com
PING letthemstare.com (178.62.111.20): 56 data bytes
64 bytes from 178.62.111.20: icmp_seq=0 ttl=53 time=147.152 ms
Kfirs-MacBook-Pro:~ silis$ ping www.letthemstare.com
ping: cannot resolve www.letthemstare.com: Unknown host
Kfirs-MacBook-Pro:~ silis$
root@letthemstare:~# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
感谢并预告。它看起来像是
A
-DNS中未定义www.letthemstare.com
的记录
此外,如果DNS区域配置正确,则无需将
letthemstare.com
添加到服务器的/etc/hosts
。当curl-vhttp://letthemstare.com/
?从服务器,我设法连接到该网站root@letthemstare:~#curl-v*在DNS缓存中找不到主机名*正在尝试127.0.1.1…*已连接到letthemstare.com(127.0.1.1)端口80(#0),但在我的Mac电脑中,DNS缓存Kfirs MacBook Pro中未找到主机名:~silis$curl-v*DNS缓存中未找到主机名*无法解析主机:letthemstare.com*关闭连接0 curl:~silis:(6)无法解析主机:letthemstare.com Kfirs MacBook Pro:~silis$