安装篇-安装Nginx

1. 创建配置文件

mkdir -p /usr/local/docker/nginx/{conf,conf.d,stream.d,html}

yml文件

cat > /usr/local/docker/nginx/docker-compose.yml <<'EOF'
version: '3.1'
services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    ports:
      - '80:80'
      - '443:443'
      - '8080:8080'
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./conf.d:/etc/nginx/conf.d
      - ./stream.d:/etc/nginx/stream.d
      - ./html:/usr/share/nginx/html
EOF

2. Nginx.conf

cat >/usr/local/docker/nginx/conf/nginx.conf<<'EOF'
user  nginx;
worker_processes  auto;

include /usr/share/nginx/modules/*.conf;
worker_rlimit_nofile 65535;

error_log  /var/log/nginx/error.log error;
pid        /var/run/nginx.pid;


events {
    # 多路复用 内核2.6以上版本,大大提高Nginx性能
    use epoll;
    worker_connections  65535;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    proxy_read_timeout 240s;

    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;
    access_log off;
    client_header_buffer_size 10M;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  60;

    #gzip  on;

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


stream {
    include /etc/nginx/stream.d/*.conf;
}
EOF

3. 网站配置

cat >/usr/local/docker/nginx/conf.d/web.conf<<'EOF'
server {
    listen       80;
    server_name  localhost;
    location / {
        root /usr/share/nginx/html/html80;
        index index.html index.htm;
    }
}
server {
    listen       8080;
    server_name  localhost;
    location / {
        root /usr/share/nginx/html/html8080;
        index index.html index.htm;
    }
}
EOF

创建页面

mkdir -p /usr/local/docker/nginx/html/{html80,html8080}

echo 'Hello Html80' > /usr/local/docker/nginx/html/html80/index.html
echo 'Hello Html8080' > /usr/local/docker/nginx/html/html8080/index.html

4. 启动Nginx

docker-compose up -d
posted @ 2021-03-13 23:28  直角漫步  阅读(105)  评论(0编辑  收藏  举报