docker搭建lnmp环境

 2023-12-24  阅读 2  评论 0

摘要:创建项目目录 mkdir php 创建如下项目结构 sites 目录放置项目文件 services 目录放置服务相关配置 script 放置自定义脚本 ├── Readme.md ├── -compose.yml ├── script ├── services │ ├── mariadb │ │ └── Dockerfile │ ├── nginx │ │ ├── D

docker搭建lnmp环境

创建项目目录

mkdir php

创建如下项目结构

  • sites 目录放置项目文件
  • services 目录放置服务相关配置
  • script 放置自定义脚本
├── Readme.md  ├── -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

提示:现在腾讯云新人点击注册然后实名认证后,可以点此一键领取2860元代金券,然后点此进入腾讯云活动页面参加优惠力度非常大的腾讯云3年和5年时长服务器活动,一次性买多年,免得续费贵,这样就可以获得最大的优惠折扣,省钱。

版权声明:xxxxxxxxx;

原文链接:https://lecms.nxtedu.cn/yunzhuji/131113.html

发表评论:

验证码

管理员

  • 内容1196554
  • 积分0
  • 金币0
关于我们
lecms主程序为免费提供使用,使用者不得将本系统应用于任何形式的非法用途,由此产生的一切法律风险,需由使用者自行承担,与本站和开发者无关。一旦使用lecms,表示您即承认您已阅读、理解并同意受此条款的约束,并遵守所有相应法律和法规。
联系方式
电话:
地址:广东省中山市
Email:admin@qq.com
注册登录
注册帐号
登录帐号

Copyright © 2022 LECMS Inc. 保留所有权利。 Powered by LECMS 3.0.3

页面耗时0.0121秒, 内存占用357.5 KB, 访问数据库18次

  • 我要关灯
    我要开灯
  • 客户电话
    lecms

    工作时间:8:00-18:00

    客服电话

    电子邮件

    admin@qq.com

  • 官方微信

    扫码二维码

    获取最新动态

  • 返回顶部