2013-07-10 23 views
30

Nginx'te yeniyim ve alt alan adları almaya çalışıyorum. Ben yapmak istiyorum nenginx - iki alt etki alanı yapılandırması

alan adımı almak ve eklemek (haydi example.com diyelim):

  • sub1.example.com,
  • sub2.example.com ve ayrıca
  • www.example.com mevcuttur.

Bunu Apache ile nasıl yapacağımı biliyorum, ancak Nginx gerçek kafa karıştırıcı oluyor.

Ben

Bulunduğum /etc/nginx/sites-enabled/example.com Debian 6. çalıştırıyorum:

server { 
    server_name www.example.com example.com; 
    access_log /srv/www/www.example.com/logs/access.log; 
    error_log /srv/www/www.example.com/logs/error.log; 
    root /srv/www/www.example.com/public_html; 

    location/{ 
     index index.html index.htm; 
    } 

    location ~ \.php$ { 
     include /etc/nginx/fastcgi_params; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name; 
    } 
} 

example.com ve www.örnek hizmet için çalışıyor. com.

ben gibi aynı dosyada ikinci bir sunucu blok eklemek çalıştık:

server { 
     server_name www.example.com example.com; 
     access_log /srv/www/www.example.com/logs/access.log; 
     error_log /srv/www/www.example.com/logs/error.log; 
     root /srv/www/www.example.com/public_html; 

     server { 
      server_name sub1.example.com; 
      access_log /srv/www/example.com/logs/sub1-access.log; 
      error_log /srv/www/example.com/logs/sub1-error.log; 
      root /srv/www/example.com/sub1; 
    } 
     location/{ 
      index index.html index.htm; 
     } 

     location ~ \.php$ { 
      include /etc/nginx/fastcgi_params; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME /srv/www/www.example.com/public_html$fastcgi_script_name; 
     } 
} 

şansımız yok. Herhangi bir fikir? Herhangi bir geri bildirim için minnettar olurum.

+0

Şundan bahsetmeliydim: Nihai hedef, sub1.example.com adresinin example.com/sub1 ve sub2.example.com adresine gitmek için example.com/sub2 adresine gitmesidir. Umarım bu mantıklıdır. – boredemt

cevap

43

hata sunucu bloğunun içinde bir sunucu bloğu koyuyor, ana sunucu bloğu daha sonra alt etki alanları sadece yerine aşağıdaki satırı eklemeniz gerekir

server { 
    server_name example.com; 
    # the rest of the config 
} 
server { 
    server_name sub1.example.com; 
    # sub1 config 
} 
server { 
    server_name sub2.example.com; 
    # sub2 config 
} 
4

için yeni bir tane açmak kapanmalı sunucu_adı

server_name xyz.com *.xyz.com; 

Ve Nginx'i yeniden başlatın. Bu kadar.

+9

Alt etki alanının, sunucuda farklı bir kaynağa işaret etmesini isterseniz, www.example.com konumu için olan kaynaktan daha fazla ne olabilir? – courtyen

İlgili konular