【问题标题】:Nginx reverse proxy configuration for subdomain with multiple paths多路径子域的 Nginx 反向代理配置
【发布时间】:2015-12-14 10:02:43
【问题描述】:

我的 Nginx 反向代理配置有一个问题。我的发行版是 Ubuntu 14.04

我有一个域,我们称之为 foo.bar.net,我希望 /grafana 端点重定向到我的 grafana 服务器 (localhost:3000),/sentry 端点重定向到我的哨兵服务器 (localhost:9000 ) 最后,将 /private 端点重定向到我的 django 服务器 (localhost:8001)。我正在使用 gunicorn 在 django 和 nginx 之间进行调音。

这是我尝试过的:

server {
    # listen on port 80
    listen 80 default_server;

    # for requests to these domains
    server_name foo.bar.net;

    location /sentry {
        # keep logs in these files
        access_log /var/log/nginx/sentry.access.log;
        error_log /var/log/nginx/sentry.error.log;

        # You need this to allow users to upload large files
        # See http://wiki.nginx.org/HttpCoreModule#client_max_body_size
        # I'm not sure where it goes, so I put it in twice. It works.
        client_max_body_size 0;

        proxy_pass http://localhost:9000;
        proxy_redirect off;

        proxy_read_timeout 5m;
        allow   0.0.0.0;
        # make sure these HTTP headers are set properly
        proxy_set_header Host            $host;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /grafana {
        proxy_pass http://localhost:3000;
        proxy_redirect off;

        proxy_read_timeout 5m;
        allow   0.0.0.0;
        # make sure these HTTP headers are set properly
        proxy_set_header Host            $host;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /private {
        proxy_pass http://127.0.0.1:8001;
    }

    location /private/static/ {
        autoindex on;
        alias /home/user/folder/private/static/;
    }
}

服务器甚至无法正确启动,配置未加载。

如果可能,我还希望 / 路径重定向到私有端点。

此外,我什至不确定该配置在哪里(站点可用/??)

谁能帮我解决这个问题?

非常感谢,

【问题讨论】:

    标签: django nginx proxy sentry grafana


    【解决方案1】:

    缺少一些分号和其他语法错误。查看主要的nginx错误日志以了解详细信息并一一修复。

    该配置文件的放置位置取决于您的发行版。对于其中一些,它应该是站点可用目录和指向站点启用目录中该文件的符号链接,以便快速启用和禁用站点,如果您没有站点可用和站点启用目录,则应将其放入 conf.d您的发行版中的目录。

    【讨论】:

    • 谢谢,我更改了配置,所以不再有语法错误。不过还是没有运气。我的发行版是 Ubuntu 14.04。
    猜你喜欢
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2018-03-24
    相关资源
    最近更新 更多