【问题标题】:What should i use Nginx html app or/and load balancing?我应该使用 Nginx html 应用程序或/和负载平衡什么?
【发布时间】:2020-01-20 12:50:08
【问题描述】:

我有一个 index.html 应用程序,它使用 nginx 执行 js 应用程序。 https://github.com/daleharvey/pacman

我想用 3 个应用程序容器和一个负载平衡来 dockerize 这个应用程序,他选择了 3 个容器中的 1 个循环算法。

但是我的html应用是用nginx的,我的负载均衡也是用nginx的?

我的 docker-compose.yml:

version: '3'

services:
  pacman1:
    build: ./pacman
  pacman2:
    build: ./pacman
  pacman3:
    build: ./pacman

   nginx:
    image: nginx:latest
    container_name: production_nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    ports: ['8000:80']

  redis:
    image: redis
    ports: ['6379']

我的 html 应用程序的 Dockerfile:

#Start with current nginx
FROM nginx:latest
#Update package manager and install git
RUN apt-get update && apt-get install -y \
        git
#Clean the html root dir
RUN rm -R /usr/share/nginx/html/
#Clone pacman app from git
RUN git clone https://github.com/daleharvey/pacman.git /usr/share/nginx/html/
#Modify files for web serving
RUN chmod -R 755 /usr/share/nginx/html/*
RUN chown -R www-data /usr/share/nginx/html/*

EXPOSE 3000

#USAGE:
# docker run --name pacman -d -p 8080:80 pacman

我的 nginx.conf

worker_processes 4;

events { worker_connections 1024; }

http {

        upstream mysite {
              least_conn;
              server pacman1:3000;
              server pacman2:3000;
              server pacman3:3000;
        }

        server {
          listen 8080;
              server_name _;
          root /usr/share/nginx/html;
          index index.html;
              location / {
                proxy_pass http://mysite;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
              }
        }
}   

请问,为什么它不起作用?因为 nginx 有默认端口 80 ?如何在没有 nginx 的情况下运行我的 html 应用程序?谢谢。

【问题讨论】:

    标签: html docker nginx docker-compose dockerfile


    【解决方案1】:

    Nginx 是运行您的 HTML 应用程序的工具。您将需要 Nginx(不错的选择)或其他一些 Web 服务器(例如 Apache)来运行 HTML 应用程序。

    你可以使用 NodeJS 或包含服务器的东西来构建你的应用程序,但是使用 Nginx 可能是最好的解决方案。

    【讨论】:

    • 是的,但我想在我的 html 应用程序上进行代理和负载平衡。我应该在 nginx 中使用 traefik 吗?还是带有 nginx html 应用的 nginx 代理?
    • 我对 traefik 没有任何经验,但您可以使用 HAProxy 或 nginx 之类的东西,如您所说。我的问题是关于为什么需要这种负载平衡的更高层次的问题?此配置会将容器放在同一台机器上。也许您应该考虑使用 docker swarm 或 Kubernetes,这样您就可以扩展 pacman
    猜你喜欢
    • 2016-09-28
    • 1970-01-01
    • 2010-10-25
    • 2022-06-22
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多