网站首页

centos7 docker 安装配置nginx

中文Lee 2021/12/01 3005人围观
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 配置目录

相关推荐

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

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

  • CentOS下php安装imagick扩展

    1、安装ImageMagic[root@localhost download]# wget http://www.imagemagick.org/download/ImageMagick.tar.gz[root@localhost download]# tar -xzvf ImageMagick[r...

  • centos7通过yum安装JDK1.8

    安装之前先检查一下系统有没有自带open-jdk命令:rpm -qa |grep javarpm -qa |grep jdkrpm -qa |grep gcj如果没有输入信息表示没有安装。如果安装可以使用rpm -qa | grep java |&n...

  • JAVA 前后端分离jwt 工具类

    package com.lup.util;import com.auth0.jwt.JWT;import com.auth0.jwt.algorithms.Algorithm;import com.auth0.jwt.interfaces.DecodedJWT;import com.auth0.jw...

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

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

  • [LuPHP] PHPMVC精简框架第一讲(基本MVC框架配置)

    LuPHP是一个精简版的PHPMVC框架,该框架经历了N个高可用系统的测验(数据存储量千万级别,并发1000),该框架结合了市面上流行的PHP框架,去除了臃肿的代码;本框架遵循即用即写的原则,做到项目中绝不存在多余(实际根本用不上)代码!该框架作者历经10年以上项目研发经验,总结并写出一套适合自己的...

  • docker 容器支持中文

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

  • 编程的程序员们,你们有语言崇拜么?比如PHP是世界上最好的语言

    有个有关程序员语言界的段子:问,你如何让一个论坛的人吵起来?答,PHP是世界上最好的语言。“PHP是世界上最好的语言”,虽然身在IT界,但说实话,这句话直到去年才明白,还是公司里招了个PHP程序员,问的他这句话到底是什么意思。大学中学的语言的话,FoxBase、C、C++,VB,Java,Ruby,...