2013-03-22 79 views
1

我在我的django(gunicorn)應用程序前面運行nginx。我要撥打的電話:將nginx中的子域url重寫爲後端服務器

api.mydomain.com

被重定向到:

本地主機:8080/API

我現在有這個,但是這顯然沒有按't work:

server { 
     listen  80; 
     server_name api.mydomain.com; 
     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_redirect off; 

    location/{ 
     index index.html index.htm; 
     proxy_pass http://localhost:8080/api; 
       } 
    } 

謝謝!

回答

1

添加新位置塊這樣

location ~ api.mydomain.com 
{ 
    fastcgi_pass localhost:8080; 
    fastcgi_param SCRIPT_FILENAME $document_root/Django script's folder's name/$fastcgi_script_name; 
} 
3

您可以將代理通過與重寫

server { 
    listen  80; 
    server_name api.mydomain.com; 
    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_redirect off; 

    location/{ 
     index index.html index.htm; 
     rewrite ^(.*)$ /api$1 break; 
     proxy_pass http://localhost:8080; 
    } 

}