网站首页

centos7 docker 安装配置nginx

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

相关推荐

  • js websocket

    <!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script src="https://www.lizh...

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

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

  • CentOS下php安装imagick扩展

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

  • php7下安装event扩展

    一·、安装支持库libevent,需要编译高版本(这里以最新版本release-2.1.8-stable为例)1. wget -c https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent...

  • centos7/linux 服务器 添加新硬盘并挂载

    一、查看现有磁盘设备  fdisk -l  发现/dev/sdb 为新加的硬盘;二、开始分区  fdisk /dev/sdb  fdisk -l    #再次查看分区情况,已经有了/dev/sdb1三、创建文件系统,并格式化  mkfs.ext4 /dev/sdb1四、将新分区挂在到文件系统  mk...

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

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

  • Scheduled 定时任务

    Scheduled 定时任务1 cron表达式指定定时器执行时间// 固定每天1点执行,无论上一次执行完没有,到时间会再执行。@Scheduled(cron = "0 0 1/1 * ?")//每一个小时执行一次@Scheduled(cron = "0 0 * * * ?") //每天上午...

  • centos7 docker 安装配置nginx

    第一步:docker pull nginx第二步:宿主机文件映射Nginx里的配置访问页面目录位置 /data/nginx/html主配置文件nginx.conf位置 /data/nginx/nginx.confnginx.conf文件内容###################user  ...