docker演示nginx反向代理

注:此处部分简单说明省略

一、拉取镜像

docker pull nginx:stable

二、编写配置

1. docker-compose.yml配置

version: '3.1'

networks:
  shared:
    external:
      name: shared

services:
  nginx:
    image: nginx:stable
    container_name: nginx
#    restart: always
    ports:
      - 80:80
      - 443:443
      - 8088:8088
    volumes:
      - ${PWD}/config/nginx.conf:/etc/nginx/nginx.conf
      - ${PWD}/log/nginx:/var/log/nginx
      - ${PWD}/../apps/html:/usr/share/nginx/html
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    networks:
      - shared

2. nginx.conf配置

# 定义Nginx运行的用户和用户组
user  nginx;

# nginx进程数,通常设置成和cpu的数量相等
worker_processes  4;

# 全局错误日志定义类型,[debug | info | notice | warn | error | crit]
error_log  /var/log/nginx/error.log warn;

# 进程pid文件
pid        /var/run/nginx.pid;

# 单个进程最大连接数(最大连接数=连接数+进程数)
events {
    worker_connections  1024;
}


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;

    server {
        # 如果使用docker容器,必须暴露该端口
        listen       8088;
        server_name  172.20.228.138;

        location / {
            # 如果使用容器,可以使用容器本身的ip,可以使用docker0的ip,也可以使用宿主机ip
            # proxy_pass http://172.18.0.14:9200/;
            proxy_pass http://172.17.0.1:9200;
            # proxy_pass http://172.20.228.138:9200;
            index  index.html index.htm index.jsp;
        }
    }

}

三、启动容器

四、查看结果

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值