Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 代理';docker集装箱之间的集装箱装卸_Ruby On Rails_Nginx_Docker_Docker Compose - Fatal编程技术网

Ruby on rails 代理';docker集装箱之间的集装箱装卸

Ruby on rails 代理';docker集装箱之间的集装箱装卸,ruby-on-rails,nginx,docker,docker-compose,Ruby On Rails,Nginx,Docker,Docker Compose,我的docker设置如下 rails api后端 mysql数据库 redis数据库 节点/反应前端(网页包) 为前端服务的nginx (rails后端目前正在通过内置puma服务器提供服务-我想我会将其移动到运行node应用程序的同一台nginx服务器上) 我的问题是前端会在后端请求内容,但这不起作用 我在nginx上设置了一个代理,如下所示: #nginx.conf server { listen 8080; # Always serve index.html for a

我的docker设置如下

  • rails api后端
  • mysql数据库
  • redis数据库
  • 节点/反应前端(网页包)
  • 为前端服务的nginx
  • (rails后端目前正在通过内置puma服务器提供服务-我想我会将其移动到运行node应用程序的同一台nginx服务器上)

    我的问题是前端会在后端请求内容,但这不起作用

    我在nginx上设置了一个代理,如下所示:

    #nginx.conf
    
    server {
        listen 8080;
    
        # Always serve index.html for any request
          location / {
            # Set path
            root /wwwroot/;
            try_files $uri /index.html;
          }
    
          location /api/ {
            proxy_pass http://127.0.0.1:3000;
          }
    }
    
    但当我启动api调用时,nginx日志中会出现以下内容:

    nginx-server | 2017/05/13 20:56:08 [error] 5#5: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 172.21.0.1, server: , request: "POST /api/authenticate HTTP/1.1", upstream: "http://127.0.0.1:3000/api/authenticate", host: "localhost:8080", referrer: "http://localhost:8080/"
    nginx-server | 172.21.0.1 - - [13/May/2017:20:56:08 +0000] "POST /api/authenticate HTTP/1.1" 502 575 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" "-"
    
    我没有看到任何东西击中彪马服务器

    我不确定我应该去哪里找。这是我的docker compose文件的问题还是nginx问题(或两者都有)。 我已将我的docker-compose.yml包含在下面:

    version: '2'
    
    services:
      nginx:
        build:
          context: .
          dockerfile: docker.nginx
        image: pt-nginx
        container_name: nginx-server
        ports:
          - "8080:8080"
        volumes:
          - wwwroot:/wwwroot
    
      webpack:
        build:
          context: ./frontend
          dockerfile: docker.webpack
        image: pt-webpack
        container_name: react-frontend
        ports:
          - "35729:35729"
        volumes:
          - ./frontend:/app
          - /app/node_modules
          - wwwroot:/wwwroot
      db:
        build:
          context: ./backend
          dockerfile: docker.mysql
        image: pt-mysql
        container_name: mysql-server
    
        env_file: ./backend/.env
        ports:
          - "3306:3306"
        volumes:
          - ./sql/data/:/var/lib/mysql
    
      redis:
        build:
          context: ./backend
          dockerfile: docker.redis
        image: pt-redis
        container_name: redis-server
    
      app:
        build:
          context: ./backend
          dockerfile: docker.rails
        image: pt-rails
        container_name: rails-server
    
        command: >
          sh -c '
          rake resque:start_workers;
          bundle exec rails s -p 3000 -b 0.0.0.0;
          '
        env_file: ./backend/.env
        volumes:
          - ./backend:/usr/src/app
          - /Users/mh/Pictures/ROR_PT/phototank:/Users/martinhinge/Pictures/ROR_PT/phototank
        ports:
          - "3000:3000"
        expose:
          - "3000"
        depends_on:
          - db
          - redis
    
    volumes:
      wwwroot:
        driver: local
    

    问题是您的nginx服务正在请求localhost(127.0.0.1)的上游。但是应用程序位于另一个容器中(具有另一个IP)。您可以通过DNS在
    app
    上引用rails应用程序,因为它们都位于默认网络中。nginx配置中的上游类似于
    proxy\u passhttp://app:3000;取而代之

    阅读更多关于网络的信息,具体如下:

    在web容器中,到db的连接字符串如下所示postgres://db:5432,从主机上看,连接字符串类似于postgres://{DOCKER_IP}:8001


    我按照建议进行了更改,但nginx不识别“app”,我得到了:
    2017/05/14 09:54:06[emerg]11#11:host not found in upper“app”in/etc/nginx/nginx.conf:43 nginx:[emerg]host not found in upper“app”in/etc/nginx/nginx.conf:43
    -我是否需要使用env variablesIt因为没有链接,所以可以这样做:。但默认情况下,它们不应该是必需的。您能否尝试将
    docker exec
    放入nginx容器,并查看是否可以ping
    app
    ?我之前的评论中的错误出现在我尝试构建时:
    docker compose build app
    。是的,我可以ping
    app
    ,这没有意义。你能为
    应用程序发布
    Dockerfile
    吗?该错误是nginx错误。对我来说,这听起来像是
    构建
    步骤可能会启动
    nginx
    服务,但我不确定原因。你完全正确。它在nginx docker文件中。首先,它将nginx.conf从主机复制到容器,然后启动nginx。现在,我已经将nginx.conf从主机映射到docker-compose.yml文件中的容器,因此我不必重新生成nginx.conf更改。此外,我已经从dockerfile中删除了startup…简言之,它可以工作!!!谢谢你的帮助!!