温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Docke如何部署nginx并配置

发布时间:2022-03-16 17:33:55 来源:亿速云 阅读:217 作者:iii 栏目:web开发

本篇内容介绍了“Docke如何部署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

“Docke如何部署nginx并配置”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI