Docker Desktop配置nginx映射且自启动

1、docker拉取nginx

docker pull nginx

2、创建windows的挂载目录及需要的文件

在这里插入图片描述

2.1 conf文件新建redis.conf


worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;


    sendfile        on;

    keepalive_timeout  65;


    # 开启动态压缩
    gzip on;
    gzip_min_length 2k;
    gzip_disable msie6;
    gzip_types text/css text/javascript application/javascript image/png image/jpeg image/gif;

# 你需要代理的地址
    	server {
    		
    	}
}

2.2 conf.d创建default.conf

这边数据不放也不影响

server {
    listen       80;
    server_name  localhost;
  
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
  
    location / {  
        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;  
    #}  
}

2.3 www创建index.html

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

2.4 web存放你的前端目录

例如dist

2.5 logs文件存放log文件

例如 access.log 和error.log
在这里插入图片描述

3、创建nginx容器

docker run --name nginx -p 80:80  --restart=always -v /D/docker/nginx/www:/usr/share/nginx/html -v /D/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /D/docker/nginx/logs:/var/log/nginx -v /D/docker/nginx/conf.d:/etc/nginx/conf.d
-v /D/docker/nginx/web/dist:/home/hometextile/web/dist -d nginx:latest

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置Docker中的Nginx开机自启动,可以根据以下步骤进行操作: 1. 首先,使用命令`docker pull nginx`来拉取Nginx镜像。 2. 创建一个目录,用于挂载Nginx配置文件和其他需要的文件。 3. 将Nginx文件复制到要使用Nginx的容器中,可以使用`docker cp`命令将Nginx文件复制到容器内的指定目录中。 4. 通过`docker container update`命令设置容器随Docker启动启动,使用`--restart=always`参数。 通过以上步骤,您可以配置Docker中的Nginx开机自启动。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Docker Desktop配置nginx映射且自启动](https://blog.csdn.net/weixin_52796198/article/details/131192008)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [docker 学习 三 (docker 容器内安装nginx 并设置自动启动)](https://blog.csdn.net/TCH8502/article/details/107365414)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值