2010-12-15 16 views
11

Sunucum ansel.ms'de ve nons.js uygulamasında ansel.ms:46156 üzerinde nginx çalıştırıyorum.Adres.com/foo/bar adresini nginx ile address.com:port/bar adresine nasıl yönlendirilir?

: Bu

için

ansel.ms/rhythm 

her şeyi yönlendirir böylece

Ben

ansel.ms:46156. 


ansel.ms/rhythm/sub/path 

Bu-mevcut siteleri benim dosyasıdır

ansel.ms:46156/sub/path 

haline gelmelidir kurulum nginx istiyorum

upstream rhythm { 
    server ansel.ms:46156; 
} 

server { 
    listen 80; 
    server_name ansel.ms www.ansel.ms; 
    access_log /srv/www/ansel.ms/logs/access.log; 
    error_log /srv/www/ansel.ms/logs/error.log; 

    location/{ 
     root /srv/www/ansel.ms/public_html; 
     index index.html index.htm; 
    } 

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

    location /rhythm{ 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-NginX-Proxy true; 

     proxy_pass http://rhythm; 
     proxy_redirect off; 
    } 
} 

Gerçekten ne olduğunu anlayamıyorum (proxy_set_header şeyler), sadece kopyaladım & çeşitli kaynaklardan yapıştırdı.

Çalışmıyor.

Bana neyi değiştireceğime dair ipucu verebilir misiniz? Teşekkür ederiz!

cevap

17

Yapılandırma dosyanızdaki hatayı tespit edemiyorum; Ben de bir nginx-newbie.

user www-data; 
worker_processes 1; 
error_log /var/log/nginx/error.log; 
pid  /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

http { 
    include  /etc/nginx/mime.types; 
    access_log /var/log/nginx/access.log; 
    sendfile  on; 
    keepalive_timeout 65; 
    tcp_nodelay  on; 

    server { 

     listen *:80; ## listen for ipv4 
     access_log /var/log/nginx/localhost.access.log; 
     location /cabaret { 
       rewrite /cabaret(.*) $1 break; 
       proxy_pass http://127.0.0.1:8085; 
       proxy_redirect  off; 
       proxy_set_header Host    $host; 
       proxy_set_header X-Real-IP  $remote_addr; 
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     } 
    } 
} 

o http://myhost/cabaret ile çalışmaz, çünkü bir çizgi http://myhost/cabaret/ veya benzeri carabet izlediği sürece, mükemmel değildir:

Ama burada http://myhost/cabaret/foo/barhttp://myhost:8085/foo/bar yönlendirir benim tam nginx.conf yapılandırma dosyasıdır http://myhost/cabaret/foo/bar.

+5

Teşekkürler! Takip eden eğik çizgi problemini şu şekilde düzeltebilirsiniz: 'server {... server_name_in_redirect off; ...} 've konumunuza şöyle bir eğik çizgi eklemelisiniz:' konum/ritim/{... '(ancak yeniden yazmamaya gerek yok!) –

+0

Bu bir 'kenara' benziyor ama siz de kullanıyorsunuz nginx, POST istekleri için günlüğe kaydetmenizi sağlar. GET isteklerimi yalnızca iyi kaydedebilirim, ancak POST isteklerinden vücut yanıtını kaydetmede sorun yaşıyorum. Sadece biraz anlayışın olabileceğini düşündüm. Sorum şu adreste yayınlandı: http://stackoverflow.com/questions/4939382/logging-post-data-from-request-body –

+0

Bu soruyu ihtiyaç duyduğum zaman içinde bulmuş olmaktan çok memnunum. Anselm Eickhoff için ekstra ponus ile. – Kawa