docker如何搭建lnmp環(huán)境

這篇文章主要介紹了docker如何搭建lnmp環(huán)境的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇docker如何搭建lnmp環(huán)境文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。

目前創(chuàng)新互聯(lián)建站已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、阿圖什網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

創(chuàng)建項(xiàng)目目錄

mkdir php

創(chuàng)建如下項(xiàng)目結(jié)構(gòu)

  • sites 目錄放置項(xiàng)目文件

  • services 目錄放置服務(wù)相關(guān)配置

  • 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

# 設(shè)置時(shí)區(qū)為上海
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

# 設(shè)置時(shí)區(qū)為上海
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環(huán)境基本搭建完畢,下面我們針對(duì)php解析做相關(guān)的配置

修改services/nginx/nginx.conf,可根據(jù)需求自行修改

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目錄下文件

該目錄是各個(gè)項(xiàng)目的配置文件,可根據(jù)需求配置單個(gè)或多個(gè)服務(wù)

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

啟動(dòng)服務(wù)

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

上述的步驟根據(jù)網(wǎng)速的docker的配置執(zhí)行時(shí)間個(gè)不相同,因?yàn)閜hp中編譯了些許擴(kuò)展,也可根據(jù)自身需求做響應(yīng)的刪減
通過瀏覽器訪問http://127.0.0.1:81,如果看到了phpinfo的輸出信息,那么恭喜你,你的lnmp環(huán)境已經(jīng)部署完成

關(guān)于“docker如何搭建lnmp環(huán)境”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“docker如何搭建lnmp環(huán)境”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁(yè)題目:docker如何搭建lnmp環(huán)境
URL網(wǎng)址:http://muchs.cn/article6/pgooog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、品牌網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)營(yíng)銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作