当前位置:   article > 正文

docker运行nginx挂载前端html页面步骤_docker nginx部署html

docker nginx部署html

1.常用docker命令

1.docker ps -a 查看所有容器
2.docker ps查看存活的容器 
3.docker rm 删除容器 
4.docker stop 停止容器运行 
5.docker logs 容器id 查看容器日志
6.docker images 查看镜像 
7.docker rmi 删除镜像
8.docker exec nginx nginx -s reload 重新加载conf文件
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.准备数据卷目录

# mkdir -p /etc/nginx/conf.d 
# mkdir -p /data/docker/nginx/logs
# mkdir -p /data/docker/nginx/html
# mkdir -p /data/docker/nginx/ssl
  • 1
  • 2
  • 3
  • 4

3.配置nginx.conf

vi /data/docker/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
	worker_connections  1024;
}


http {
	include       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  logs/access.log  main;

	sendfile        on;
	#tcp_nopush     on;

	#keepalive_timeout  0;
	keepalive_timeout  65;
	include /etc/nginx/conf.d/*.conf; #这里需要填容器路径
	#gzip  on;

}
  • 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

域名路由conf文件
vi /etc/nginx/conf.d/www.daqianshijie2024.com.conf

server {
    listen 80;
    #listen 443 ssl http2;
    server_name www.daqianshijie2024.com;

    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #ssl_prefer_server_ciphers on;
    #ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";

    #ssl_certificate cert/ydtvip.shihuak.com.pem;
    #ssl_certificate_key cert/ydtvip.shihuak.com.key;
    #ssl_stapling on;
    #ssl_stapling_verify on;
    resolver 114.114.114.114 8.8.8.8 8.8.4.4 223.5.5.5 valid=300s;
    resolver_timeout 200s;
    #ssl_trusted_certificate cert/ydtvip.shihuak.com.pem;
    client_max_body_size 200m;
    client_body_buffer_size 200m;
      
    location / {
            alias  /mnt/web/daqianshijie2024/h5/; # 该项目以nginx/html为根目录的相对路径,如果是在html目录下的dist文件夹,就修改为html/dist即可。
            index index.html;
            try_files $uri $uri/ /index.html; # 要加上这句,否则只能显示主页,无法显示其他页面
    }
}
  • 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

4.运行nginx容器

docker run -d --name nginx --rm -p 80:80 \  #--rm表示启动后删除容器,但是有bug看不到日志,所以先去掉正常启动容器当
-v /etc/nginx/conf.d:/etc/nginx/conf.d:rw \ #www.daqianshijie2024.com.conf放域名解析的地方,左边是宿主机路径,右边是docker容器内路径
-v /data/docker/nginx/logs:/var/log/nginx:rw \ #放日志文件的地方
-v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:rw \ #放ngin.conf文件的地方,这里include需要填容器路径也就是/etc/nginx/conf.d/*.conf
-v /mnt/web/daqianshijie2024/h5:/mnt/web/daqianshijie2024/h5:rw \ #放html静态文件挂载的地方,必须挂载到html文件路径下
nginx:1.20.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

带ssl证书

docker run -d --name nginx --rm  -p 80:80 -p 443:443 \
-v /etc/nginx/conf.d:/etc/nginx/conf.d:rw \
-v /data/docker/nginx/logs:/var/log/nginx:rw \
-v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:rw \
-v /mnt/web/daqianshijie2024/h5:/mnt/web/daqianshijie2024/h5:rw \
-v /data/docker/nginx/ssl:/ssl:rw \  #ssl文件挂载
nginx:1.20.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

5.docker容器处理sh脚本

docker stop nginx;
docker run -d --name nginx --rm -p 80:80 \
-v /etc/nginx/conf.d:/etc/nginx/conf.d:rw \
-v /data/docker/nginx/logs:/var/log/nginx:rw \
-v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:rw \
-v /mnt/web/daqianshijie2024/h5:/mnt/web/daqianshijie2024/h5:rw \
nginx:1.20.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/980448
推荐阅读
相关标签
  

闽ICP备14008679号