docker搭建nginx

1、拉取镜像

docker pull nginx:latest
docker images
image.png

2、创建对应的文件夹

mkdir -p /home/nginx/{conf,conf.d,html,log}
image.png

3、创建容器并且运行

docker run --privileged=true --name nginx -d -p 80:80  -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/log:/var/log/nginx -v /home/nginx/html:/usr/share/nginx/html nginx

3、配置文件
conf.d

server {
        listen       80;
        server_name  192.168.2.134;

        location / {
                proxy_pass http://192.168.2.134:8888/;
        }

       location /oss/ {
                proxy_pass http://192.168.2.134:9999/;
        }

        #location / {
        #        alias   /usr/share/nginx/html/h5/;
        #        try_files $uri $uri/ /index.html;
        #       index  index.html index.htm;
        #}
}

nginx.conf

#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;
        client_max_body_size 8m;
        gzip  on;

        keepalive_timeout  65;

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

你可能感兴趣的:(docker搭建nginx)