查看“Docker nginx”的源代码
←
Docker nginx
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=直接拉的= ==只挂载web目录 == <pre> #最好指定版本 #docker pull nginx #这个才够小巧 docker pull nginx:1.16-alpine [root@localhost npm4compose]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx 1.16-alpine ef04b00b089d 4 weeks ago 20.4MB #其它的要100M mkdir -p /data/nginx/html docker run --name nginx1.16 -p 80:80 -d -v /data/nginx/html:/usr/share/nginx/html ef04b00b089d 目录什么的和下面一样 mkdir /data/nginx/html -p docker run --name mynginx -p 80:80 -d -v /data/nginx/html:/usr/share/nginx/html nginx [root@localhost ~]# cat /data/nginx/html/index.html hello #直接访问就可以了 改web目录而已要做的事 </pre> ==挂载web目录 配置目录 log目录等等 == <pre> 在用户的家目录下创建 nginx 目录及其子目录 conf.d、conf.crt 和 html,创建 logs 目录及其子目录 nginx 和 letsencrypt: $ mkdir -p nginx/{conf.d,conf.crt,html} $ mkdir -p logs/{nginx,letsencrypt} 创建 nginx/nginx.conf 文件,内容如下: 复制代码 user nginx; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 2048; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 10M; include /etc/nginx/conf.d/*.conf; } 复制代码 然后创建 nginx/conf.d/default.conf 文件,内容如下: 复制代码 upstream web{ server myweb:3000; } server { listen 80; listen [::]:80; server_name filterinto.com www.filterinto.com; location ^~ /.well-known/acme-challenge/ { default_type "text/plain"; root /usr/share/nginx/html; } location = /.well-known/acme-challenge/ { return 404; } location / { proxy_pass http://web; } } 复制代码 其中 /.well-known/acme-challenge/ 目录是 certbot 工具在生成证书时创建的。接下来创建文件 nginx/html/index.html 文件,内容如下: 复制代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Let's Encrypt First Time Cert Issue Site</title> </head> <body> <h1>Hello HTTPS!</h1> <p> Just used for the very first time SSL certificates are issued by Let's Encrypt's certbot. </p> </body> </html> 复制代码 这个页面也是 certbot 在生成证书时需要用到的。最后让我们启动容器(在用户的家目录下执行下面的命令): 复制代码 $ docker run -d \ -p 80:80 \ -v $(pwd)/nginx/conf.d:/etc/nginx/conf.d:ro \ -v $(pwd)/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \ -v $(pwd)/logs/nginx:/var/log/nginx \ -v $(pwd)/nginx/html:/usr/share/nginx/html \ --restart=always \ --name=gateway \ --network=webnet \ nginx:1.14 </pre> [https://www.cnblogs.com/sparkdev/p/9163162.html 为 docker 中的 nginx 配置 https] https://docs.docker.com/samples/library/nginx/ https://www.nginx.com/blog/deploying-nginx-nginx-plus-docker/ [https://www.jianshu.com/p/9cd58ea389bc 有意思Docker部署(五):Nginx and 反向代理配置] =build= <pre> # # Dockerfile for building Nginx images # # https://github.com/evan886/docker-lnmp.git # FROM centos:centos7 MAINTAINER evan <evan886@gmail.com> ENV TZ "Asia/Shanghai" #Yum RUN yum -y update && \ yum install -y gcc automake autoconf libtool make gcc-c++ vixie-cron wget zlib file openssl-devel sharutils zip bash vim cyrus-sasl-devel libmemcached libmemcached-devel libyaml libyaml-devel unzip libvpx-devel openssl-devel ImageMagick-devel autoconf tar gcc libxml2-devel gd-devel libmcrypt-devel libmcrypt mcrypt mhash libmcrypt libmcrypt-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel bison libtool-ltdl-devel net-tools && \ yum clean all #Nginx RUN mkdir -p /data/apps/nginx && cd /tmp && \ wget http://nginx.org/download/nginx-1.11.5.tar.gz && \ tar xzf nginx-1.11.5.tar.gz && \ cd /tmp/nginx-1.11.5 && \ ./configure \ --prefix=/data/apps/nginx && \ make -j2 && make install # make install #--prefix=/data/apps/nginx \ #--with-http_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module \ #--with-http_gzip_static_module --with-http_stub_status_module --with-debug && \ #make -j2 && \ #make install #配置nginx #ENV HTTP_PHP_CONFIG \\\n\\\t#php\\\n\\\tlocation ~ \\\\.php$ {\\\n\\\t\\\troot html;\\\n\\\t\\\tfastcgi_pass php7:9000;\\\n\\\t\\\tfastcgi_index index.php;\\\n\\\t\\\tfastcgi_param SCRIPT_FILENAME /usr/local/nginx/html\$fastcgi_script_name;\\\n\\\t\\\tinclude fastcgi_params;\\\n\\\t}\\\n\\\n\\\t #RUN sed -i -e "s@# deny access to .htaccess files, if Apache@${HTTP_PHP_CONFIG}# deny access to .htaccess files, if Apache@" /usr/local/nginx/conf/nginx.conf EXPOSE 80 443 #启动nginx ENTRYPOINT ["/data/apps/nginx/sbin/nginx", "-g", "daemon off;"] docker build --tag evan886/centos-nginx:v1 -f nginx/Dockerfile . docker run --name nginx -p 80:80 -v /data/apps/nginx/html/:/data/apps/nginx/html/ -d -it 9a4ccef0484d 登入容器: docker exec -it jenkins /bin/bash docker push evan886/centos-nginx:v1 </pre> ==on debian== <pre> mkdir nginx cd nginx # 改国内源 vi sources.list deb http://mirrors.cloud.tencent.com/debian stretch main contrib non-free deb http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free #deb http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free #deb http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free deb-src http://mirrors.cloud.tencent.com/debian stretch main contrib non-free deb-src http://mirrors.cloud.tencent.com/debian stretch-updates main contrib non-free #deb-src http://mirrors.cloud.tencent.com/debian stretch-backports main contrib non-free #deb-src http://mirrors.cloud.tencent.com/debian stretch-proposed-updates main contrib non-free wget -c https://nginx.org/download/nginx-1.12.2.tar.gz vi Dockerfile #For Debian 9## 指定镜像 FROM debian:stretch-slim # 指定管理员 MAINTAINER linuxsa.org # 执行命令安装编译库文件 RUN rm -f /etc/apt/sources.list ADD sources.list /etc/apt/sources.list RUN apt-get clean all && apt update && apt install -y gcc gcc g++ make openssl libssl-dev libpcre3 libpcre3-dev #RUN yum install -y gcc gcc-c++ make openssl-devel pcre-devel # RUN apt-get update && apt-get install -y --no-install-recommends g++ gcc libc6-dev make && rm -rf /var/lib/apt/lists* # 添加解压nginx包到/tmp目录下 RUN mkdir -p /tmp ADD nginx-1.12.2.tar.gz /tmp # 不用什么tar 解压 ,进入目录进行编译安装 RUN cd /tmp/nginx-1.12.2 && ./configure --prefix=/usr/local/nginx --without-http_gzip_module && make -j 2 && make install # 删除容器内置配置文件 RUN rm -f /usr/local/nginx/conf/nginx.conf # 复制本地配置文件到容器内 COPY nginx.conf /usr/local/nginx/conf # 声明暴露端口 EXPOSE 80 # 启动容器Nginx服务,指定全局命令daemon off保证服务在前台运行不会关闭 CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"] vi nginx.conf #这个要优化一下 user root; worker_processes auto; error_log logs/error.log info; pid logs/nginx.pid; events { use epoll; } http { include mime.types; default_type application/octet-stream; log_format main '$upstream_addr $remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; # 动静分离 server { listen 80; server_name localhost; # 动态请求转发给tomcat处理 location / { proxy_pass http://www.example.com; } # 静态资源请求交给nginx处理 location ~ \.(html|css|js|jpg|png|gif)$ { root /opt/webapps/ROOT; } } } </pre> =域名配置= <pre> 当然 ngignx 配置文件要 -v docker run –name=nginx -p 80:80 -v /nginx/conf.d:/etc/nginx/conf.d -d nginx server { listen 80; server_name www.aaa.com自己域名; location / { proxy_pass http://宿主机ip:容器对外的端口号; #就可以mediawiki的喽 } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 或者作dns A 母机 打开你的域名即可看到效果,当然你得先把域名解析到宿主机的ip上面。 </pre> [https://www.jianshu.com/p/6b317192480c docker搭建nginx实现反代 配置多域名以及多端口号] =Troubleshooting= == An image does not exist locally == <pre>[root@localhost ~]# docker push evan886/centos-nginx:v1 The push refers to repository [docker.io/evan886/centos-nginx] An image does not exist locally with the tag: evan886/centos-nginx 我写错了 应该是 docker push evan886/nginx:v1 docker run --name nginx -p 80:80 -v /var/www/html:/usr/local/nginx/html -d -it imagesid docker run --name nginx -p 80:80 -v /var/www/html:/usr/local/nginx/html -d -it evan886/nginx:v1 </pre> == docker nginx 503== 打开503 404 什么的 在对应目录创建个html页面就好了 == nginx make 少了&&== <pre>mkdir -p /data/apps/nginx && cd /tmp && \ wget http://nginx.org/download/nginx-1.11.5.tar.gz && \ tar xzf nginx-1.11.5.tar.gz && \ cd /tmp/nginx-1.11.5 && \ ./configure --prefix=/data/apps/nginx && \ #一开始这里少了&& make -j 2 && make install</pre> == Docker pull 出现的 http: TLS handshake timeout == http://www.cnblogs.com/wozixiaoyao/p/6059780.html ==mysql err == <pre> WARNING: The following packages cannot be authenticated! mysql-community-client mysql-client mysql-community-server mysql-server E: There were unauthenticated packages and -y was used without --allow-unauthenticated </pre> =更新源= <pre> 进入容器后,首先更新一下镜像源,这样下载速度会快很多,输入以下命令: set -ex \ && sed -i 's@security.debian.org@mirrors.aliyun.com@' /etc/apt/sources.list set -ex \ && sed -i 's@deb.debian.org@mirrors.aliyun.com@' /etc/apt/sources.list apt-get update </pre> =参考= [https://www.vultr.com/docs/how-to-compile-nginx-from-source-on-ubuntu-16-04 Compile Nginx From Source on Ubuntu ] [https://www.jyoryo.com/index.php/archives/96.html Nginx 1.15.X Linux Debian/Ubuntu 源码编译安装 LNMP之Nginx] [https://www.cnblogs.com/visec479/p/5145624.html 源码编译安装Nginx] [https://www.jianshu.com/p/fcd0e542a6b2 Docker多容器部署LNMP环境] [https://www.cnblogs.com/jie-fang/p/7927643.html Docker基础-使用Dockerfile创建nginx镜像] [http://www.ruanyifeng.com/blog/2018/02/nginx-docker.html Nginx 容器教程] https://docs.docker.com/samples/library/nginx/ [https://github.com/docker-library/mysql/blob/f279c9cc0d20407a2c4d9465adae6b077dcf1b51/5.6/Dockerfile dockerfile debian:stretch-] [https://segmentfault.com/a/1190000004990514 Docker容器的Nginx实践] [https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/ Deploying NGINX and NGINX Plus on Docker] [https://blog.csdn.net/youcijibi/article/details/88781014 docker运行nginx为什么要使用 nginx -g 'daemon off;'] [https://www.cnblogs.com/roverliang/p/8431206.html docker 使用入门,创建一个Nginx服务器] [https://blog.csdn.net/u011781521/article/details/80464220 Docker(三)----Dockerfile搭建Nginx环境与文件挂载] [https://blog.csdn.net/qq_26641781/article/details/80883192 Docker nginx安装与配置挂载] [https://blog.csdn.net/u013494765/article/details/78258270 使用docker部署nginx容器] [https://blog.csdn.net/wuapeng/article/details/80974417 docker之Dockerfile实践用dockerfile构建nginx环境] [https://blog.csdn.net/vbaspdelphi/article/details/53172729 docker 部署简单nginx服务器] [https://www.cnblogs.com/zhhuihui/p/docker_z.html 使用dockerfile构建nginx镜像] [https://blog.csdn.net/wangfei0904306/article/details/77623400 Docker部署nginx并修改配置文件] [https://blog.csdn.net/jason_jeson/article/details/78200623 Docker 通过Nginx镜像部署Vue项目] [https://www.jianshu.com/p/6b317192480c docker搭建nginx实现反代 配置多域名以及多端口号] [https://www.cnblogs.com/sparkdev/p/9163162.html 为 docker 中的 nginx 配置 https] [https://www.cnblogs.com/Jarvin/p/5796193.html docker中使用nginx容器代理其他容器] [https://www.jianshu.com/p/8228d261c6ff docker下nginx反向代理和负载均衡配置] [[category:ops]] [[category:容器]][[category: container]]
返回至
Docker nginx
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
我的导航
关于我
shell
python
ops
linuxchina.net
blog.linuxchina
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息