2013-03-22 81 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; 
    } 

}