SpringCloudAlibaba实战教程系列  

docker:官网    中文官网

docker:镜像官网

Docker 命令大全

一、拉取nginx官方镜像,镜像更多解释

     1、登录docker 镜像官网搜索nginx,找到制定的版本拉去,这里使用默认最新nginx版本。

docker pull nginx:latest

Docker(部署常见应用):Docker部署Nginx

   2、查看docker的镜像

docker images

Docker(部署常见应用):Docker部署Nginx

 

 二、启动docker应用

     1、简单启动,命令弊端,nginx需要取单独修改配置文件和查看nginx打印日志,所以不建议使用这种方式,推荐使用第二种方式

## 构建container
docker run -d  --name nginx -p 80:80 nginx
## 启动,执行后就可以访问了http://localhost/  
docker start nginx

    2、推荐启动方式,修改配置可以持久化和查看日志 

   第一步、首先创建nginx在本地映射目录。www用于映射静态文件,logs存储日志,conf存在nginx配置信息,conf.d统一配置服务监听信息

mkdir -p /root/nginx/www /root/nginx/logs /root/nginx/conf /root/nginx/conf/conf.d

  第二步、创建使用的文件

touch /root/nginx/conf/conf.d/default.conf  /root/nginx/conf/nginx.conf /root/nginx/www/index.xml

在default.conf文件中插入一下内容,容器内部的路径/etc/nginx/conf.d/

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-07-01
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-13
  • 2021-10-13
  • 2021-12-02
  • 2021-11-27
  • 2022-01-17
  • 2021-08-05
相关资源
相似解决方案