首页 > 系统相关 >centos下docker-compose搭建lnmp环境

centos下docker-compose搭建lnmp环境

时间:2022-09-04 16:44:06浏览次数:65  
标签:compose centos lnmp nginx html conf php root

 

所有操作均在root权限下进行

sudo -i

 

1、新建文件夹【/root/lnmp】和文件【/root/lnmp/docker-compose.yml】

mkdir /root/lnmp
vi /root/lnmp/docker-compose.yml

 

2、写入yml文件内容

version: "3"  
services:   
  nginx:    
     image: nginx:latest
     container_name: c_nginx
     ports:
      - "80:80"
     #centos文件夹【/root/lnmp/nginx/html】和容器文件夹【/usr/share/nginx/html】进行绑定,并设rw权限
     #centos文件【/root/lnmp/nginx/conf/default.conf】和容器文件【/etc/nginx/conf.d/default.conf】进行绑定
     volumes:
      - /root/lnmp/nginx/html/:/usr/share/nginx/html/:rw
      - /root/lnmp/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
     #设置上海时区
     environment:
      TZ: "Asia/Shanghai"
     #容器自启
     restart: always
     #加入lnmp的网络
     networks:
      - lnmp
  php:
    image: php:7.3.29-fpm
    container_name: php_01
    volumes:
      - /root/lnmp/nginx/html/:/var/www/html/:rw
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - lnmp

  mysql:
    image: mysql:5.6
    container_name: mysql56
    ports:
      - "3306:3306"
    volumes:
      - /root/lnmp/mysql/data:/var/lib/mysql/:rw
    restart: always
    networks:
      - lnmp
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
      TZ: "Asia/Shanghai"
networks:   
  #新建自定义网络【lnmp】
  lnmp:

  

 

 

3、新建文件夹【/root/lnmp/nginx】、【/root/lnmp/nginx/conf】和文件【/root/lnmp/nginx/conf/default.conf】

mkdir /root/lnmp/nginx
mkdir /root/lnmp/nginx/conf
vi /root/lnmp/nginx/conf/default.conf

  

4、写入conf文件内容

server {
    listen       80;
    root   /usr/share/nginx/html;
    index   index.html index.php;


    # 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;
    }

    location / {
        index  index.html index.php ;
        try_files $uri $uri/ /index.php?$query_string;
        autoindex  on;
    }


    location ~ \.php$ {
        #php_01是yml里的容器名
        fastcgi_pass   php_01:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
    }

}

  

5、进入lnmp文件夹启动yml文件

cd /root/lnmp
docker-compose up -d

  

 

标签:compose,centos,lnmp,nginx,html,conf,php,root
From: https://www.cnblogs.com/zwgbk/p/16655361.html

相关文章

  • 在Centos中yum安装和卸载软件的使用方法
    在Centos中yum安装和卸载软件的使用方法安装方法安装一个软件时yum-yinstallhttpd安装多个相类似的软件时yum-yinstallhttpd*安装多个非类似软件时yum-yinstallht......
  • CentOS-6.5-x86_64-bin-DVD1.iso 下载
    CentOS-6.5-x86_64-bin-DVD1.iso下载_gz153016的博客-CSDN博客_centos-6.5-i386-bin-dvd1.iso https://blog.csdn.net/gz153016/article/details/50557077 ......
  • CentOS 7替换默认软件源
    安装CentOS7后,默认源在国外,可以替换为国内的源以提升访问速度参考https://mirrors.ustc.edu.cn/help/centos.htmlsudovi/etc/yum.repos.d/CentOS-Base.repo,写入如下内......
  • Magical Compose——性能监控
    我报名了GoldstoneProjectPhase1Challenge——瓜分100,000奖池,这是我的第一篇文章,点击查看活动详情背景在android开发中,无论是基于xml开发还是compose的view系统,开......
  • centos7升级php版本
    1.概述本篇博客主要记录如何在centos7.9升级php版本。2.操作过程添加php的yum源rpm-Uvhhttps://rpms.remirepo.net/enterprise/remi-release-7.rpm在/etc/yum.repo......
  • Centos7 常用优化脚本
    #!/bin/bash#服务器一键优化工具functiondefine_check_network(){echo主机名为`hostname-f`pingwww.baidu.com-c6}functiondefine_yum(){#......
  • LNMP构建
    lnmp架构LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。......
  • centos /dev/mapper/cl-root 100% 解决方法
    centos/dev/mapper/cl-root100%解决方法-青木天阁-博客园 https://www.cnblogs.com/elizwy/p/7722898.html本来是要在虚拟机上安装grpc进行测试的,结果发现gradle......
  • Centos7安装配置jdk环境
    1、从官网上下载jdk的tar包https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html2、通过工具,将tar包传到Linux系统中,/usr/local3......
  • 如何查看已安装的CentOS版本信息
    如何查看已安装的CentOS版本信息_Linux教程_Linux公社-Linux系统门户网站 https://www.linuxidc.com/Linux/2014-12/110748.htm如何查看已安装的CentOS版本信息:1)[root......