2015-10-10 32 views
15

80 numaralı bağlantı noktasında www.example.com ve api.example.com'u çalıştırmak istiyorum.Nginx birden çok sunucu aynı bağlantı noktasını dinlemeyi engelliyor

Bu benim sahip olduğum şey. Tüm googles ping'im aşağıdaki kodlara yol açıyor. Ama bu işe yaramıyor.

server { 
     listen 80 default_server; 
#  listen [::]:80 default_server ipv6only=on; 

     root /var/www/example.com/html/example/app; 
     index index.html index.htm; 

     # Make site accessible from http://localhost/ 
     server_name www.example.com www.example.org; 

     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       try_files $uri $uri/ =404; 
       # Uncomment to enable naxsi on this location 
       # include /etc/nginx/naxsi.rules 
     } 

     location /bower_components { 
       alias /var/www/example.com/html/example/bower_components; 
     } 

     location /scripts { 
       alias /var/www/example.com/html/example/scripts; 
     } 

     location /content { 
       alias /var/www/example.com/html/example/content; 
     } 

     location /api { 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_pass http://127.0.0.1:3836; 
     } 
} 

server { 
     listen 80 
     server_name api.example.com 

     location/{ 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_pass http://127.0.0.1:3836; 
     } 
} 

Nedeni bilmiyorum. Bu konuda herhangi bir öneriniz var mı?

Teşekkürler!

+0

Kök, 'api.ornek.com' sanal ana bilgisayarında eksik. – C1sc0

cevap

12

ayrı iki /etc/nginx/sites-available/www.example.com dosyaları (eğer gerekmez, ancak daha net olacaktır) ve /etc/nginx/sites-available/api.example.com

api.example.com dosyanın conten

server { 
     listen 80 
     server_name api.example.com 
     root /var/www/api.example.com/html/example/app; #also add a root dir here 
     location/{ 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_pass http://127.0.0.1:3836; 
     } 
} 

www.örnek oluştur .com içeriği:

server { 
     listen 80 default_server; 
#  listen [::]:80 default_server ipv6only=on; 

     root /var/www/example.com/html/example/app; 
     index index.html index.htm; 

     # Make site accessible from http://localhost/ 
     server_name www.example.com www.example.org; 

     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       try_files $uri $uri/ =404; 
       # Uncomment to enable naxsi on this location 
       # include /etc/nginx/naxsi.rules 
     } 

     location /bower_components { 
       alias /var/www/example.com/html/example/bower_components; 
     } 

     location /scripts { 
       alias /var/www/example.com/html/example/scripts; 
     } 

     location /content { 
       alias /var/www/example.com/html/example/content; 
     } 

     location /api { 
       proxy_set_header Host $host; 
       proxy_set_header X-Real-IP $remote_addr; 
       proxy_pass http://127.0.0.1:3836; 
     } 
} 

ve nihayet etki sağlar: sudo ln -s /etc/nginx/sites-available/www.example.com /etc/nginx/sites-enabled/www.example.com ve sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/api.example.com

+0

"Ayrıca, www.example.com sanal ana bilgisayarını dosya yapılandırmanıza ekleyin:" ile ne demek istiyorsunuz anlamadım. Daha fazlasını açıklar mısınız? –

+1

Bu işe yaramazsa, web sayfasına ulaşmayı denerseniz, tail -f/var/log/nginx/error.log' komutunun çıktısı nedir? – C1sc0

+0

Çok teşekkür ederim. Hallettim. –

İlgili konular