网站首页

centos7 docker 安装配置nginx

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

相关推荐

  • centos7通过yum安装JDK1.8

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

  • java 生成缩略图 imageIO异常:Unsupported Image Type, 不支持图像类型【附解决办法】

    最近再做图片生成缩略图功能,发现大部分的图片都可以生成缩略图,但是偶尔有几个图片会报异常:Unsupported Image Type;几经折腾,发现报异常的图片格式为CMYK 格式,我们常见的图片格式都是RGB格式的,所以我们要把CMYK格式的图片转换成RGB格式的,网上有些办法转化后图片颜色会丢...

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

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

  • php7下安装event扩展

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

  • PHP性能优化方案

    常用性能优化方案1.使用单引号替换双引号,单引号在运行的时候不检查运行引号内部的变量,执行效率是双引号的两倍;2.使用PHP内置的数组操作方法,PHP内置的数组操作方法的运行效率是自行编写代码的10倍以上;3.使用字符串函数替换正则函数,例如:使用 str_replace 替换&...

  • php的性能优化

    1.尽量静态化:   如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍。   当然了,这个测试方法需要在十万级以上次执行,效果才明显。   其实静态方法和非静态方法的效率主要区别在内存:静态方法...

  • Linux内核调优(大并发场景下)

    为了让系统能够支持更大的并发,除了必须安装event扩展(或libevent扩展)之外,优化linux内核也是重中之重,以下优化每一项都非常非常重要,请务必按逐一完成。打开文件 /etc/sysctl.conf,增加以下设置#该参数设置系统的TIME_WAIT的数量,如果超过默认值则会被立即清除 ...

  • mysqlbinlog 保存为sql文件。

    执行如下命令:mysqlbinlog -vv --base64-output=decode-rows binlog路径 --result-file=要保存的sql路径例如:/www/server/mysql/bin/mysqlbinlog -vv --base64-output=decode-row...