关于docker:dockerNginx代理本地目录

10次阅读

共计 3247 个字符,预计需要花费 9 分钟才能阅读完成。

启动挂载容器,开启文件服务

ssl_certificate cert/5900588_test.zk.limengkai.work.pem;
ssl_certificate_key cert/5900588_test.zk.limengkai.work.key;


docker run -tdi --rm -v  /containers/nginx:/etc/nginx -v /amydata:/amydata -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime -p 443:443 -p 80:80  --name  nginx1  nginx 

docker 代理本地目录

1. 抉择要挂载的目录

博主抉择 /amydata 目录对外裸露

2. 配置 nginx 文件

保留在宿主机 /a_nginx_conf/nginx.conf 批改 38 行,你要进行裸露的文件夹

location / {
    #代理本地文件夹
    root /amydata;
    autoindex on;
}
mkdir -p /a_nginx_conf

mkdir -p /amydata

残缺的 /a_nginx_conf/nginx.conf

worker_processes  4;

events {worker_connections  1024;}

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

http {
    include       mime.types;
    default_type  application/octet-stream;
    
    # 避免中文乱码
    charset utf-8;


    # 默认为 on,显示出文件的确切大小,单位是 bytes。# 改为 off 后,显示出文件的大略大小,单位是 kB 或者 MB 或者 GB
    autoindex_exact_size off;

    # 默认为 off,显示的文件工夫为 GMT 工夫。# 留神: 改为 on 后,显示的文件工夫为文件的服务器工夫
    autoindex_localtime on;


    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;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        
        #配置跨域
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

        location / {
            #代理本地文件夹
            root /amydata;
            autoindex on;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {root   html;}

    }
}

启动挂在容器,开启文件服务

对外裸露 服务器的 50000 端口 到 nginx 内

docker run -tdi --rm -v  /a_nginx_conf/nginx.conf:/etc/nginx/nginx.conf -v /amydata:/amydata -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime -p 50000:80  --name  nginx1  nginx

docker run -tdi --restart=always -v  /a_nginx_conf/nginx.conf:/etc/nginx/nginx.conf -v /amydata:/amydata -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime -p 50000:80  --name  nginx1  nginx

拜访 即可 http://(域名)|(ip):50000

/amydata

nginx 配置文件

find / -name "*nginx.conf*"
find: '/proc/1/map_files': Operation not permitted
find: '/proc/6/map_files': Operation not permitted
find: '/proc/11/map_files': Operation not permitted
/etc/nginx/nginx.conf

原有配置文件

[email protected]:/# cat < /etc/nginx/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;
}

批改的配置文件

保留在宿主机 /a_nginx_conf/nginx.conf

worker_processes  1;

events {worker_connections  1024;}

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

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  /var/log/nginx/access.log  main;

  
    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        
        #配置跨域
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

        location / {
            #代理本地文件夹
            root /amydata;
            autoindex on;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {root   html;}

    }
}

命令记录

docker stop nginx1 && docker rm nginx1

docker run -tdi  --name  nginx1  nginx  /bin/bash
正文完
 0