简体   繁体   English

具有多个路径的子域的Nginx反向代理配置

[英]Nginx reverse proxy configuration for subdomain with multiple paths

I have a situation here with my Nginx reverse proxy configuration. 我的Nginx反向代理配置在这种情况下。 My distribution is Ubuntu 14.04 我的发行版是Ubuntu 14.04

I have a domain, let's call it foo.bar.net, and I want the /grafana endpoint to redirect to my grafana server (localhost:3000), the /sentry endpoint to redirect to my sentry server (localhost:9000) and finally, the /private endpoint to redirect to my django server (localhost:8001). 我有一个域,我们称其为foo.bar.net,我希望/ grafana端点重定向到我的grafana服务器(localhost:3000),/ sentry端点重定向到我的哨兵服务器(localhost:9000),最后,/ private端点重定向到我的django服务器(localhost:8001)。 I am using gunicorn for the tuneling between django and nginx. 我正在用gunicorn进行django和nginx之间的调和。

Here is what I tried : 这是我尝试的:

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

The server won't even start correctly, the config is not loading. 服务器甚至无法正确启动,配置未加载。

I would also like the / path to redirect to the private endpoint if possible. 如果可能,我还希望/路径重定向到私有端点。

Additionally, I am not even sure where to put this configuration (sites-available/??) 另外,我什至不知道将此配置放在何处(sites-available / ??)

Can anyone help me with that ? 有人可以帮我吗?

Thanks a lot, 非常感谢,

There are some missing semicolons and other syntax errors. 缺少一些分号和其他语法错误。 Look at main nginx error log for details and fix them one by one. 查看主要的nginx错误日志以获取详细信息,并一步一步地对其进行修复。

Where to put that config file depends on your distribution. 将该配置文件放在何处取决于您的分发。 For some of them it should be sites-available directory and symlink to that file inside sites-enabled directory for quick enabling and disabling sites, if you don't have sites-available and sites enabled directory, you should put it into conf.d dir in your distribution. 对于其中的某些站点,它应该是站点可用目录,并在站点启用目录内该文件的符号链接用于快速启用和禁用站点,如果您没有站点可用和站点启用目录,则应将其放入conf.d中。目录中的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM