Docker的nginx反向代理配置

时间:2019-09-13 13:44:42

标签: docker http nginx

我很难确定要在域中加载本地运行的dockerized Web应用程序的配置。

以下是:

docker-compose.yml

version: "3"
services:
  ui:
    build: ./ui
    volumes:
      - ./ui:/app/sr
    container_name: ui
    ports:
      - "4200:4200"
    networks:
      - webnet
    links:
      - api
  api:
    build: ./api
    ports:
      - "0.0.0.0:5000:5000"
    volumes:
      - ./api:/app
    container_name: api
    networks:
      - webnet

networks:
  webnet:

nginx / conf.d / ui.example.conf

server {
listen 80;
#listen [::]:80;

server_name ui.example.de www.ui.example.de;

location / {
proxy_pass http://ui:4200/;
#proxy_buffering off;
#proxy_set_header X-Real-IP $remote_addr;
}
}

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

它在ip下的本地计算机上运行 http://138.246.XXX.XX:4200以及http://138.246.XXX.XX中 但是,当我尝试使用http://ui.example.com通过网络访问时,它会显示错误503。

enter image description here

我还尝试了使用docker网络中的ip和我的机器ip,即ui.example.conf中的代理传递中的http://138.246.XXX.XX:4200

[注意] :我从nginx / sites_enabled中删除了默认设置。现在这是空的,因为我只尝试使用nginx进行反向代理。 有人知道吗,我在这里想念什么?

0 个答案:

没有答案