zoukankan      html  css  js  c++  java
  • Docker 配置 nginx

    ## 拉取 nginx 镜像
    # docker pull nginx
    ## 启动镜像
    # docker run --rm --name nginx-test -p 8080:80 -d nginx
    
    ## 宿主机创建几个 nginx 的文件夹,用于存放容器中 nignx 的配置信息和日志信息
    # mkdir -p ~/Desktop/nginx/www ~/Desktop/nginx/conf/ ~/Desktop/nginx/logs
    ## 拷贝容器中 nginx 的 conf
    # docker cp 容器ID:/etc/nginx/nginx.conf ~/Desktop/nginx/conf/
    
    ## 启动容器
    docker run -d -p 8080:80 -p 9050-9090:9050-9090 --name nginx 
      -e "TZ=Asia/Shanghai" 
      -v  ~/Desktop/nginx/www:/usr/share/nginx/html 
      -v  ~/Desktop/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 
      -v  ~/Desktop/nginx/logs:/var/log/nginx 
      nginx
    

    启动后就可以随意玩耍了,在 ~/Desktop/nginx/www 文件夹中创建一个 index.html,里面写上 hello world!
    访问 localhost:8080 即可访问到刚刚创建的 index.html文件里面的 hello world! 了。
    同样的,修改 ~/Desktop/nginx/conf/ 下的 nginx.conf 让后重启镜像(或者进入镜像中 ./nginx -s reload )
    即可让修改生效。学习 nginx 的配置文件的各种用法,再也不用安装编译工具及库文件,./configure make && make install 了。

    附录:

    pull 下来的 nginx 有很多的模块
    
    # docker exec -it 容器ID /bin/sh; exit
    # which nginx
    /usr/sbin/nginx
    # cd /usr/sbin
    # ./nginx -V
    nginx version: nginx/1.17.10
    built by gcc 8.3.0 (Debian 8.3.0-6) 
    built with OpenSSL 1.1.1d  10 Sep 2019
    TLS SNI support enabled
    configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.17.10/debian/debuild-base/nginx-1.17.10=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
    

    这样就可以在宿主机配置 nginx.conf 文件,折腾 nginx,简单又方便。

  • 相关阅读:
    laravel队列
    php程序内存优化之数组操作优化
    swoole4创建Mysql连接池
    MySQL创建索引
    mysql索引命中规则
    Redis数据类型及使用场景
    Redis高可用集群-哨兵模式(Redis-Sentinel)
    网站架构优化性能
    PHP实现Redis分布式锁
    微软公司面试题
  • 原文地址:https://www.cnblogs.com/manastudent/p/12919542.html
Copyright © 2011-2022 走看看