小飞知识库 | YeLu🤠MiLu🤪 小飞知识库 | YeLu🤠MiLu🤪
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

YeLu

爱技术的YeLu🤠
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • linux笔记

  • nginx笔记

    • nginx介绍

    • nginx安装

      • gz压缩包方式安装
      • docker安装nginx
        • 安装
        • 创建挂载的目录
        • 创建配置文件
        • 重载配置文件
        • 启动nginx
      • docker-compose安装nginx
    • nginx进阶

  • docker笔记

  • windows笔记

  • ElasticSearch

  • 虚拟机

  • 监控系统

  • 运维
  • nginx笔记
  • nginx安装
YeLu🤠
2023-03-29
目录

docker安装nginx

特别注意:

​ 将容器里面的文件映射到本地的时候,一定要现在本地创建文件,然后将容器内部需要映射的文件的内容拷贝到本地文件里面,之后才能启动

# 安装

docker pull nginx
1

# 创建挂载的目录

mkdir -p /data/nginx/{conf,conf.d,html,logs}
1

# 创建配置文件

vim  /data/nginx/conf/nginx.conf
1
查看conf内容

这个是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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vim /data/nginx/conf.d/default.conf
1
查看conf内容

这个是default.conf参考内容

server {  
    listen       80;  
    server_name  localhost;  
  
    #charset koi8-r;  
    #access_log  /var/log/nginx/log/host.access.log  main;  
  
    location / {  
        #root   /data/nginx/html;  
        root   /usr/share/nginx/html;  
        index  index.html index.htm;  
        #autoindex  on;  
        #try_files $uri /index/index/page.html;  
        #try_files $uri /index/map/page.html;  
    }  
  
    #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;  
    #}  
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
vim /data/nginx/html/index.html   这个html就是默认访问nginx看到的页面可以自定义
1
查看html内容
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>nginx牛皮</title>
</head>
<body>
<div id="datetime">
    <script>
        setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 1000);
    </script>
</div>
</body>  
1
2
3
4
5
6
7
8
9
10
11
12

# 重载配置文件

docker exec -it 容器id service nginx reload
1

# 启动nginx

docker run --name nginx -d -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx:latest
1

#冒号前是本地路径(需要绝对路径),冒号后是容器中的路径

-v 是挂载的意思 将容器里面的配置文件挂载到本地 (使用-v挂载文件夹(推荐)

这种方法是在启动的时候使用-v将容器内部的文件夹挂载(映射)到本地的某个路径下,以后以后可以直接在本地修改,不需要进入容器内部.)

#nginx
最近更新: 2024/12/25, 11:44:08
gz压缩包方式安装
docker-compose安装nginx

← gz压缩包方式安装 docker-compose安装nginx→

最近更新
01
服务端配置
07-30
02
frp 安装
07-30
03
Prometheus采集Springboot应用
02-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | YeLu🤠MiLu🤪 | MIT License 蜀ICP备2024116879号 | 川公网安备51012202001998号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
欢迎你,我的朋友
看板娘