Py学习  »  NGINX

Docker撰写nginx代理不重定向

scorewinner • 4 年前 • 239 次点击  

我有一个Ubuntu服务器,在一个Docker容器中构建了一个nginx代理,在另一个容器中构建了一个nginx Web服务器,它们都在同一个网络中,并且可以看到彼此,但是代理不会重定向到Web服务器,访问我的网站时总是会出现此错误:

proxy      | 2018/09/05 15:30:27 [alert] 8#8: 1024 worker_connections are not enough
proxy      | 2018/09/05 15:30:27 [error] 8#8: *4086 upstream prematurely closed connection while reading response header from upstream, client: 172.18.0.1, server: , request: "GET / HTTP/1.0", upstream: "http://XX.XX.XX.XX:80/", host: "test.com"

以下是我的文件:

docker-compose.yml公司

version: '3'
networks:
    webnet:

services:
  proxy:
    build: ./proxy
    container_name: proxy
    networks:
      - webnet
    ports:
      - 80:80

  website:
    container_name: website
    build: ./nginx
    volumes:
      - ./config/default.conf:/etc/nginx/conf.d/
    networks:
      - webnet

DockerFile代理

FROM nginx
RUN rm /etc/nginx/nginx.conf

COPY proxy.conf /etc/nginx/nginx.conf

## proxy.conf

events {
  worker_connections 1024;
}

http {
        server {
                listen 80;
                server_name website;

                location / {
                        proxy_pass http://website;
                }
        }
}
```

DockerFile nginx Web服务器

FROM nginx

RUN rm /usr/share/nginx/html/*
COPY test.com /usr/share/nginx/html

## nginx webserver default.conf
server {
    server_name test.com www.test.com;
    root /usr/share/nginx/html;
    index index.php;
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37988
 
239 次点击  
文章 [ 1 ]  |  最新文章 4 年前
scorewinner
Reply   •   1 楼
scorewinner    5 年前

我刚刚意识到,我确实将代理容器重定向到了自身,现在就修复了它。^^

DockerFile代理

server {
  listen 80;
  server_name proxy;

  location / {
      proxy_pass http://website/
  }
}

DockerFile nginx Web服务器

server {
    server_name website;
    root /usr/share/nginx/html;
    index index.php;
}