网站首页

centos7 docker 安装配置nginx

中文Lee 2021/12/01 3165人围观
linux  

第一步:docker pull nginx


第二步:宿主机文件映射Nginx里的配置

访问页面目录位置 /data/nginx/html

主配置文件nginx.conf位置 /data/nginx/nginx.conf

nginx.conf文件内容

###################

user  root;

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;

    autoindex  on;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    client_max_body_size 100M;

    client_header_buffer_size    128k;

    large_client_header_buffers  4  128k;

}

###################

配置目录 conf.d ,目录下的子配置文件(一般最少一个default.conf文件),位置 /data/nginx/conf.d


default.conf文件内容

####################

server {

    listen       80;

    server_name  localhost;

    #charset koi8-r;

    access_log  /var/log/nginx/host.access.log  main;

    location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm;

        autoindex  on;

    }

    #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;

    #}

}

####################

最后启动Nginx容器


docker run  --name my_nginx  -d -p 80:80   -v /data/nginx/html:/usr/share/nginx/html   -v /data/nginx/log:/var/log/nginx  -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf:ro  -v /data/nginx/conf.d:/etc/nginx/conf.d  nginx



参数:

- -name 容器名称,命名为myNginx

-d 后台运行

-p 主机端口与容器端口映射,本地80端口映射到容器80端口

-v 目录映射

/data/nginx/html > /usr/share/nginx/html 静态页面文件

/data/nginx/log > /var/log/nginx 日志目录

/data/nginx/nginx.conf > /etc/nginx/nginx.conf:ro 只读方式映射配置文件

/data/nginx/conf.d > /etc/nginx/conf.d 配置目录

相关推荐

  • html js 前端下载文件并且给文件重命名

    今天有一个需求,甲方要求 下载的文件名为 “标题.doc”,而我数据库存储的是时间戳(123072747621318656.doc),同时我又不想修改后端代码了,想着让前端实现一下 前端下载并指定名称。下面是下载的实现代码<div onclick="downLoad()">downLoa...

  • centos7 docker安装openjdk并运行jar包

    第一步:docker pull openjdk第二步:创建一个java_app的数据卷 docker volume create java_app第三步:将jar包上传到/var/lib/docker/volumes/java_app/_data/下,然后启动镜像第四步:启动docker ...

  • 如何安装php7的event扩展

    最近api系统遇到了高并发的瓶颈,想通过workerman重构。在看workerman文档时发现这么一句话:Event扩展不是必须的,当业务需要支撑上万并发连接时,推荐安装Event,能够支持巨大的并发连接。如果业务并发连接比较低,例如1000并发连接,则可以不用安装。如果无法安装Event扩展,可...

  • 一款超级好用的驾校预约系统-公众号预约系统【驾校预约系统】

    “驾校教练微信预约系统”可用于“驾校微信预约系统”、“教练微信预约系统”,其主要预约对象是学车学员,学员可依据教练信息、自身空闲时间合理选择预约时间,及时掌握学车学时。本系统一共包含三个端(学员端/教练端/管理端):1、学员在线预约教练(可单笔支付,可购买课时);2、教练收到预约推送,教练可以自由开...

  • docker 容器支持中文

    客户有个需求:将table内容转换成图片显示;后端语言采用java;使用组件 HtmlImageGenerator结果发现,windows下中文不乱码,但是用docker部署到linux就乱码了所以先尝试不使用docker,结果还是乱码,然后给服务器安装中文字体(安装方法自行百度),安装好...

  • 常用PHP框架有哪些?[PHP框架排行TOP7]

    PHP是一种国内外流行的开源服务器端脚本开发语言。能适应大、中、小型项目的发展需要。PHP框架的真正开发始于PHP5。事实上,PHP4时代也有一些框架,但是由于使用的复杂性,没有一个纯粹的PHP易于使用,所以在PHP5才有很大的发展。随着PHP5面向对象功能的实现。基PHP的产品越来越多。在PHP开...

  • .htaccess文件设置某目录下所有文件禁止访问

    如网站,有些目录下的文件不允许被下载则需要设置.htaccess文件为了减少服务器压力:应将apache配置文件<Directory />    AllowOverride All</Directory> 最好修改成指定目录: <...

  • 11个代码质量审核和管理工具,程序员收藏

    如今,代码质量分析和审核已成为每个企业的基本流程。随着开源代码库使用的增加,安全性和代码质量对于构建高质量软件至关重要。不良的代码不仅会影响代码的可维护性,而且还会在某些情况下影响其性能。此外,更好的代码质量还有助于企业将来减少维护和降低成本。幸运的是,有很多审核和管理代码的工具,为开发者和程序员提...