栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker安装nginx

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker安装nginx

一、使用 docker search nginx 查看镜像来源
[root@localhost docker]# docker search nginx
NAME                             DEscriptION                                     STARS               
二、拉取镜像至本地

如拉取最新版本至本地

docker pull nginx

也可以指定版本号,不加版本号默认获取最新版本,也可以使用 docker search nginx查看镜像来源

docker pull nginx:6.2.5

三、查看本地镜像

[root@localhost docker]# docker images | grep nginx
四、安装 1、简单安装

可以使用以下命令来运行 nginx 容器:

$ docker run --name nginx-test -p 8080:80 -d nginx

参数说明:
–name nginx-test:容器名称。
-p 8080:80: 端口进行映射,将本地 8080 端口映射到容器内部的 80 端口。
-d nginx: 设置容器在在后台一直运行。

2、配置安装(可选)

新建宿主机文件存储目录:

创建nginx的数据存储和配置文件目录

mkdir -p /deploy/nginx/{conf,logs,html}

将第一步简单安装的文件夹复制到指定目录
然后按需编辑nginx相关的配置文件
如编辑conf.d的default.conf文件

upstream gateway{
	server 192.168.0.232:9999;
        server 10.10.26.34:9999;
}

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

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

    #For WebSocket upgrade header
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";    

  # 静态文件映射
    root  /usr/share/nginx/html;
    #  访问路径代理
    location ~* ^/(auth|code|upms|gen|weixin|mall|payapi|doc|webjars|swagger-resources) {
           proxy_pass http://gateway;
           #proxy_set_header Host $http_host;
           proxy_connect_timeout 60s;
           proxy_send_timeout 300s;
           proxy_read_timeout 300s;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    #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;
    }

     location = /index.html {
        root   /usr/share/nginx/html;
        add_header Cache-Control "no-cache, no-store";
    }

    # 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;
    #}
}

启动容器

docker run --restart=always --name nginx -d -p 9909:8
0 -v /deploy/nginx/html:/usr/share/nginx/html -v /deploy/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /deploy/nginx/conf.d:/etc/nginx/conf.d -v /deploy/nginx/logs:/var/log/nginx nginx
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/333517.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号