9. Nginx

docker-compose

version: '3.1'
services:
  nginx:
    restart: always
    image: nginx
    container_name: nginx
    ports:
      - 81:80
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./wwwroot:/usr/share/nginx/wwwroot

创建conf文件夹

mkdir conf
cd conf
vi nginx.conf

编辑nginx.conf

worker_processes 1;
events {
    worker_connections 1024;
}


http {
    include  mine.types;
    default_type  application/octet-stream;
    sendfile  on;
    keepalive_timeout 65;


    # 配置虚拟主机1
    server {
        # 监听的ip和端口
        listen 80;
        # 虚拟主机名称:配置ip地址
        server_name 192.168.91.130
        # 所有的请求都以 / 开始,所有的请求都可以匹配此location
            location / {
                # 使用root指令制定虚拟主机目录,即网页存放目录
                # 比如访问http://ip/index.html, 将找到/usr/local/docker/nginx/wwwroot/html80/index.html
                # 比如访问http://ip/item/index.html, 将找到/usr/local/docker/nginx/wwwroot/html80/item/index.html
                root /usr/share/nginx/wwwroot/html81
                # 指定欢迎页面,按从左到右顺序查找
                index index.html index.htm
            }
    }

基于端口

docker-compose

version: '3.1'
services:
  nginx:
    restart: always
    image: nginx
    container_name: nginx
    ports:
      - 81:80
      - 9000:9000
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./wwwroot:/usr/share/nginx/wwwroot

nginx.conf

worker_processes 1;
events {
    worker_connections 1024;
}




http {
    include  mine.types;
    default_type  application/octet-stream;
    sendfile  on;
    keepalive_timeout 65;




    # 配置虚拟主机1
    server {
        # 监听的ip和端口
        listen 80;
        # 虚拟主机名称:配置ip地址
        server_name 192.168.91.130
        # 所有的请求都以 / 开始,所有的请求都可以匹配此location
            location / {
                # 使用root指令制定虚拟主机目录,即网页存放目录
                # 比如访问http://ip/index.html, 将找到/usr/local/docker/nginx/wwwroot/html80/index.html
                # 比如访问http://ip/item/index.html, 将找到/usr/local/docker/nginx/wwwroot/html80/item/index.html
                root /usr/share/nginx/wwwroot/html81
                # 指定欢迎页面,按从左到右顺序查找
                index index.html index.htm
            }
    
    }
    server {
        listen 9000;
        server_name 192.168.91.130
            location / {
                root /usr/share/nginx/wwwroot/html9000
                index index.html index.htm
            }
    

基于域名

基于IP

惊群问题

对于只需要一个资源的任务,nginx同时分配多个资源,造成资源浪费的问题

反向代理

负载均衡

发布了17 篇原创文章 · 获赞 0 · 访问量 70

猜你喜欢

转载自blog.csdn.net/qq_37106658/article/details/105619557