如何在Ubuntu上设置nginx虚拟主机

时间:2015-06-06 13:04:49

标签: nginx dns host vhosts

问题:不需要的nginx vhost重定向到www.domain.com

  1. 我按如下方式配置了我的服务器/ dns:
  2. root @ letthemstare:〜#cat / etc / hostname
    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
    
    1. Magento安全/不安全网址已配置为http://letthemstare.com/
    2. 托管DNS - 域已配置为letthemstare.com
    3. 然而,每当我在浏览器中使用letthemstare.com网址时,它都会被重定向到www.letthemstare.com(无法访问)。 我想我的vhost配置文件中有错,但我无法识别它。

      请帮助我清除不需要的重定向到www域,并将所有www URL重定向到非www域(我的if条件应该这样做,但现在我怀疑一切)。

      谢谢并提前。

1 个答案:

答案 0 :(得分:0)

看起来像A - www.letthemstare.com的记录未在DNS中定义。

此外,如果您的DNS区域配置正确,则无需将letthemstare.com添加到服务器的/etc/hosts

相关问题