【Docker技术内幕】(九)使用docker安装Nginx

目录

一、准备工作

1、安装docker

2、设置加速镜像

二、开始安装

1、创建目录

2、新建配置

3、启动容器

四、常见问题

1、排除favicon.ico不存在的日志

2、解决nginx下加载eot|otf|ttf|woff|svg等404 错误问题


一、准备工作

1、安装docker

参考

【Docker技术内幕】(四)Linux环境下安装docker

2、设置加速镜像

vim /etc/docker/daemon.json
 
{
 
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
 
}
 
systemctl restart docker
systemctl enable docker

二、开始安装

1、创建目录

mkdir -p /data/nginx81/{html,logs,conf}

2、新建配置

cd /data/nginx81

vim nginx.conf

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;



    client_max_body_size     5000m;

    client_header_timeout    600;

    client_body_timeout      600;

    proxy_connect_timeout       600;

    proxy_send_timeout          600;

    proxy_read_timeout          600;

    send_timeout                600;

    keepalive_timeout 1800;



    #gzip  on;



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

    

    server {

        listen       80;

        server_name  localhost;



        location / {

            root   /usr/share/nginx/html;

            index  index.html index.htm;

        }

        

        location = /favicon.ico {

            log_not_found off;

            access_log off;

        }



    }

}

cd /data/nginx81/html

vim index.html

```

nginx-index

```

3、启动容器

docker run --name nginx81 -p 81:80 \

-v /data/nginx81/nginx.conf:/etc/nginx/nginx.conf \

-v /data/nginx81/conf:/etc/nginx/conf.d \

-v /data/nginx81/logs:/var/log/nginx \

-v /data/nginx81/html:/usr/share/nginx/html \

-d nginx

四、常见问题

1、排除favicon.ico不存在的日志

location = /favicon.ico {

        log_not_found off;

        access_log off;

}

2、解决nginx下加载eot|otf|ttf|woff|svg等404 错误问题

location ~* .(eot|otf|ttf|woff|woff2|svg)$ {

    root   /usr/share/nginx/html/test-report-static;

    add_header Access-Control-Allow-Origin *;

}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

forest_long

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值