1

我在我的 django (gunicorn) 应用程序前面运行 nginx。我想打电话给:

api.mydomain.com

被重定向到:

本地主机:8080/api

我现在有了这个,但这显然不起作用:

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;
    }
}

谢谢!

4

2 回答 2

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;
    }

}
于 2013-03-22T20:55:00.113 回答
1

像这样添加一个新的位置块

location ~ api.mydomain.com
{
    fastcgi_pass localhost:8080;
    fastcgi_param SCRIPT_FILENAME $document_root/Django script's folder's name/$fastcgi_script_name;
}
于 2013-03-22T20:52:06.713 回答