nginx - Proxy_pass 从 foo.website.com 到 localhost :xxxx using nginx on docker - not localhost on physical machine

标签 nginx localhost docker

我试图让 foo.website.com 显示 localhost:8181 上的内容,并让 bar.website.com 显示 localhost:3000。但是,我希望它从 docker 框中显示 localhost(其中 :8181 和 :3000 显示我想要的),而不是我的物理机器上的 localhost(它们是空白的 - 未使用。)我正在使用 nginx这样做,nginx 配置在我的 docker 文件中。

Gaphite 在 localhost:3000 上运行,graph-explorer(更好看/支持 Graphite 前端的标签)在 localhost:8181 上 - 当我将 url 直接放入浏览器时,两者都按预期工作。 Graphite 的 manage.py 在 localhost:8080 上运行,这就是 graph-explorer 在 :8181 上的原因。

这是我在这里的第一篇文章,我是 docker/nginx 和一般网络的新手,所以如果我缺少信息/不清楚,我很乐意纠正......

nginx settings:
server {
    listen 80;
    root /opt/graphite/webapp/content;
    index index.html;

    location / {
      # checks for static file, if not found proxy to app
      try_files \$uri @app;
    }

    # The location is where I'm trying to go from
    location foo.website.com {
      # This is the port graph-explorer is running on
      proxy_pass 127.0.0.1:8181;
    }

    location @app {
        include fastcgi_params;
        fastcgi_split_path_info ^()(.*)$;
        fastcgi_pass 127.0.0.1:8080;
    }


    server_name website.com;
}

在我的主机文件中(在 docker 机器和 docker 运行的虚拟框中 - 不确定我是否应该同时拥有这两者?)
127.0.0.1 foo.website.com
127.0.0.1 bar.website.com

值得注意的是,这主要是从我在网上找到的一些东西拼凑而成的,所以如果有什么可疑的,答案可能是“马修是个白痴”。

非常感谢 :)

最佳答案

如果我理解正确,你想要:

foo.website.com 代理传递到 localhost:8181
bar.website.com 代理传递到 localhost:3000

试试这个:

server {  
    listen 80;
    server_name foo.website.com;

    # foo.website.com proxy pass to localhost:8181

    location / {
        proxy_pass http://127.0.0.1:8181;
        proxy_set_header Host $host;
    }
}
server {
    listen 80;
    server_name bar.website.com;

    # bar.website.com proxy pass to localhost:3000

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
    }
}

关于nginx - Proxy_pass 从 foo.website.com 到 localhost :xxxx using nginx on docker - not localhost on physical machine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183020/

相关文章:

localhost - WAMP 错误!安装 laravel 后 403 forbidden

windows - 通过 UNC 使用模拟主机的身份验证问题

python - 属性错误 : 'Namespace' object has no attribute 'epochs_per_eval'

Wordpress 多站点 Nginx 子目录安装无法再找到数据库

javascript - 本地和生产环境中 Node 的行为

python - 如何使用 Mac 终端在我的服务器上托管本地主机?

jar - 通过应用使用的jar文件传递环境变量

django docker-compose --> memcached 不工作

amazon-web-services - 无法使用 kubernetes 与在 AWS EC2 实例中本地创建的 Pod 通信

node.js - 限制用户访问其他用户内容的最优雅的方法是什么?