Nginx部署

3.Nginx部署

  1. 搜索Nginx 镜像

    1
    docker search nginx
  2. 拉取mysql镜像

    1
    docker pull nginx
  3. 创建容器,设置端口映射、目录映射

    1
    2
    3
    4
    5
    6
    7
    #在/root目录下创建nginx目录用于存储nginx数据信息
    mkdir ~/nginx
    cd ~/nginx
    mkdir conf
    cd conf
    #在~/nginx/conf/下创建nginx.conf文件,粘贴下面代码块的内容
    vim nginx.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    user  nginx;
    worker_processes 1;

    error_log /var/log/nginx/error.log warn;
    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;
    }
    1
    2
    3
    4
    5
    6
    docker -run -id --name=c_nginx \
    -p 80:800 \
    -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
    -v $PWD/logs:/var/log/nginx \
    -v $PWD/html:/usr/share/nginx/html \
    nginx
    • 参数说明:
      • -p 80:800:将容器的80端口映射到宿主机的80端口
      • -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:将主机当前目录下的/conf/nginx.conf挂载到容器的:/etc/nginx/nginx.conf配置目录
      • -v $PWD/html:/usr/share/nginx/html:将主机当前目录挂载到容器的/val/log/nginx日志目录

使用外部机器访问nginx

发布于

2022-08-22

更新于

2023-03-21

许可协议

# 相关文章
  1.Java部署
  2.MySQL部署
  3.Redis部署
  4.Tomcat部署
  5.MySQL部署

:D 一言句子获取中...