首页 > 系统相关 >dockerNginx代理本地目录

dockerNginx代理本地目录

时间:2022-11-03 19:24:08浏览次数:51  
标签:http 本地 etc nginx conf amydata dockerNginx 目录 log

dockerNginx代理本地目录

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

原有配置文件

root@88bd90de686b:/# 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

标签:http,本地,etc,nginx,conf,amydata,dockerNginx,目录,log
From: https://www.cnblogs.com/ltgybyb/p/16855547.html

相关文章