centos7.7+docker19.03.8+nginx1.17.9+使用浏览器测试访问

### 部署Nginx

 

1. 搜索nginx镜像

#shell

docker search nginx

 

 

2. 拉取nginx镜像

#shell

docker pull nginx

 

 

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

#shell

# 在/root目录下创建nginx目录用于存储nginx数据信息

mkdir ~/nginx

cd ~/nginx

mkdir conf

cd conf

# 在~/nginx/conf/下创建nginx.conf文件,粘贴下面内容

vim nginx.conf

 

#shell

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;

}

 

#shell

docker run -id --name=c_nginx \

-p 80:80 \

-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \

-v $PWD/logs:/var/log/nginx \

-v $PWD/html:/usr/share/nginx/html \

nginx

 

 

 

4. 使用外部机器访问nginx

 

http://192.168.3.12/

 

 

发布了27 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/huoran668/article/details/105534009