温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

docker如何搭建lnmp环境

发布时间:2022-05-26 16:44:14 来源:亿速云 阅读:121 作者:iii 栏目:大数据

这篇文章主要介绍了docker如何搭建lnmp环境的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇docker如何搭建lnmp环境文章都会有所收获,下面我们一起来看看吧。

创建项目目录

mkdir php

创建如下项目结构

  • sites 目录放置项目文件

  • services 目录放置服务相关配置

  • script 放置自定义脚本

├── readme.md ├── docker-compose.yml ├── script ├── services │ ├── mariadb │ │ └── dockerfile │ ├── nginx │ │ ├── dockerfile │ │ ├── conf.d │ │ │ └── default.conf │ │ └── nginx.conf │ ├── php │ │ └── dockerfile │ └── redis │  └── dockerfile └── sites  ├── index.html  └── index.php   8 directories, 10 files

编辑docker-compose文件

version: "3" services:   php:  build: ./services/php  # ports:   # - "9001:9000"  container_name: lnmp-php  restart: always  volumes:    - ./sites:/www  networks:   lnmp_net:   ipv4_address: 101.11.11.10  nginx:  build: ./services/nginx  ports:   - "81:80"   - "444:443"  container_name: lnmp-nginx  restart: always  volumes:    - ./sites:/www   - ./services/nginx/nginx.conf:/etc/nginx/nginx.conf   - ./services/nginx/conf.d:/etc/nginx/conf.d:rw  networks:   lnmp_net:   ipv4_address: 101.11.11.11 networks:  lnmp_net:  driver: bridge  ipam:   config:   - subnet: 101.11.11.0/20

编辑services/nginx文件

from nginx:1.17.0-alpine # 更新安装源 run sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 设置时区为上海 run apk update && apk add --upgrade \  && apk add tzdata \  && cp /usr/share/zoneinfo/asia/shanghai /etc/localtime \  && echo "asia/shanghai" > /etc/timezone \  && apk del tzdata

编辑services/php文件

from php:7.3.6-fpm-alpine3.9 # 更新安装源 run sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 设置时区为上海 run apk update && apk add --no-cache tzdata autoconf gcc g++ make zlib-dev curl-dev\  && cp /usr/share/zoneinfo/asia/shanghai /etc/localtime \  && echo "asia/shanghai" > /etc/timezone \  && apk del tzdata \  && docker-php-ext-install mysqli pdo_mysql opcache \  && pecl install grpc protobuf xdebug yaf yar swoole \  && docker-php-ext-enable xdebug yaf yar swoole grpc protobuf

以上我们的lnmp环境基本搭建完毕,下面我们针对php解析做相关的配置

修改services/nginx/nginx.conf,可根据需求自行修改

user nginx; worker_processes auto; 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;  #gzip on;  include /etc/nginx/conf.d/*.conf; }

修改services/nginx/conf.d目录下文件

该目录是各个项目的配置文件,可根据需求配置单个或多个服务

server {  listen  80;  server_name localhost;  #charset koi8-r;  #access_log /var/log/nginx/host.access.log main;   #root /usr/share/nginx/html;  root /www;  index index.php index.html index.htm;  #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 101.11.11.10:9000;   fastcgi_index index.php;   fastcgi_param script_filename $document_root$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;  #} }

启动服务

cd php && docker-compose up --build -d

上述的步骤根据网速的docker的配置执行时间个不相同,因为php中编译了些许扩展,也可根据自身需求做响应的删减
通过浏览器访问http://127.0.0.1:81,如果看到了phpinfo的输出信息,那么恭喜你,你的lnmp环境已经部署完成

关于“docker如何搭建lnmp环境”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“docker如何搭建lnmp环境”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI