Docker部署Nginx + php-fpm + Mysql + Redis

/home/nginx/conf.d下新建nginx配置default.conf

server {
    listen       80;
    server_name  localhost;

    root /var/www/html;
    index  index.html index.htm index.php;
    charset utf-8;
    
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    location ~ ^(.+\.php)(.*)$ {
        fastcgi_split_path_info       ^(.+\.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_pass php:9000;
        include        fastcgi_params;
    }
    
    location ~ /\.ht {
       deny  all;
    }
}

編寫(xiě)docker-compose.yaml,鏡像會(huì)自動(dòng)下載

version: "3.8"
services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    ports:
      - 80:80
    links:
      - php
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - /home/nginx/conf.d:/etc/nginx/conf.d
      - /home/nginx/logs:/var/log/nginx
      - /home/www:/var/www/html
    networks:
      - mynet
  php:
    image: php:8.0.3-fpm
    container_name: php
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - /home/www:/var/www/html
    networks:
      - mynet
  mysql:
    image: mysql:8
    container_name: mysql
    restart: always
    volumes:
      - /home/mysql:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=
      - TZ=Asia/Shanghai
    networks:
      - mynet
  redis:
    image: redis
    container_name: redis
    restart: always
    ports:
      - 6379:6379
    volumes:
      - /home/redis:/data
    networks:
      - mynet
networks:
  mynet:
    driver: bridge

啟動(dòng)

docker-compose up -d

在/home/www下新建index.php

<?php
  phpinfo();

訪問(wèn)地址,顯示PHP Version則Nginx+PHP配置成功
分別訪問(wèn)Mysql和Redis,均可訪問(wèn)(阿里云需要把對(duì)應(yīng)端口開(kāi)通安全組)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容