安装nginx
查询安装
[root@localhost ~]# docker search nginx
[root@localhost ~]# docker pull nginx
准备

创建一个什么都不配置nginx拿到一个nginx.conf文件和conf.d文件夹

创建文件、文件夹(只需创建logs文件夹即可log文件是运行自动挂载的)

[root@hao /usr/local/software/nginx]# tree
.
├── conf
│   ├── conf.d
│   │   └── default.conf
│   └── nginx.conf
├── html
│   ├── 50x.html
│   └── index.html
└── logs
    ├── access.log
    └── error.log

4 directories, 6 files
运行什么都不进行配置)

使用端口:8075映射80

docker run -it 
--name nginx 
-p 8075:80 
-p 8080:8080 
--privileged 
--network wn_docker_net 
--ip 172.18.12.90 
-v /etc/localtime:/etc/localtime 
-v /usr/local/software/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 
-v /usr/local/software/nginx/html:/usr/share/nginx/html 
-v /usr/local/software/nginx/conf/conf.d:/etc/nginx/conf.d 
-v /usr/local/software/nginx/logs:/var/log/nginx 
-d nginx
配置实现负载均衡

打开nginx.conf

分类/nginx/nginx_1.png  0 → 100644

完整的文件内容


user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
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;

    #myCode:
    #配置上有服务器,形成负载
    upstream activityBalance{
       server 192.168.133.100:15348 weight=1;
       server 192.168.200.113:15348 weight=1;
    }
    server{
       keepalive_requests 120;        #单连接请求上限次数
       listen    8080;                  #监听端口号

       location /api/{
        proxy_pass         http://activityBalance/api/; #反向代理服务器访问地址
        proxy_set_header   Host $host;                                             #主机ip
        proxy_set_header   X-real-ip        $remote_addr;                          #客户端访问的真实ip
        proxy_set_header   X-Fowarded-For   $proxy_add_x_forwarded_for;            #代理转发历史
        proxy_redirect     off;
       }
    }

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

完成

原文地址:https://blog.csdn.net/treadsangerbraes/article/details/134753075

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_31254.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注