Docke部署nginx并配置nginx

2019-12-06 16:01:30来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

Docke部署nginx并配置nginx

一、在docker中下载nginx镜像

 docker pull nginx

二、在宿主机中创建挂在目录

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

三、在挂在目录下新建配置文件

vim /data/nginx/conf/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

        server{
                listen 80;
                server_name localhost;   #你的serverName
                root /usr/share/nginx/html;
                index index.html;
        }

}

  四、将nginx容器映射在宿主机80端口

docker run 
--name my_nginx
-d -p 80:80  
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf   #冒号前是挂在到宿主的目录,冒号后面是容器中的目录
-v /data/nginx/log:/var/log/nginx 
-v /data/nginx/html:/usr/share/nginx/html
nginx

  在本地/data/nginx/html写一个测试页面

echo "test" >/data/nginx/html/index.html

 

 


原文链接:https://www.cnblogs.com/DevonL/p/11996496.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:linux 动态链接库查找方法;查找动态链接库位置; LIBRARY_PATH

下一篇:(办公)记事本_Linux常用的文件操作命令