日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

使用 docker 搭建 nginx+php-fpm 环境 (两个独立镜像)

發布時間:2025/3/15 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用 docker 搭建 nginx+php-fpm 环境 (两个独立镜像) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 獲取 nginx 鏡像
  • docker search nginx docker pull nginx
  • 使用nginx鏡像開啟 nginx 應用容器
  • docker run -d --name nginx -p 8080:80 -v /tmp:/usr/share/nginx/html docker.io/nginx

    說明

  • -d 后臺運行
  • --name 自定義容器名稱
  • -p 8080:80 宿主機的8080 映射到容器的80端口
  • -v 宿主機 tmp 目錄映射容器地址(nginx服務器項目默認路徑)
  • 在/tmp 目錄下新建一個 index.html 里面打個 hello nginx
    訪問 127.0.0.1:8080 正確的情況下會出現該文件內容

  • 獲取 php-fpm 鏡像
  • docker search php-fpm docker pull bitnami/php-fpm

    4.運行 php-fpm

    docker run -d -v /tmp:/usr/share/nginx/html --name php-fpm docker.io/bitnami/php-fpm
  • 查看 php-fpm IP
  • docker inspect php-fpm | grep "IPAddress"
  • 修改 nginx 配置文件 使他跟 php-fpm 關聯起來
  • #copy 配置文件 docker cp nginx:/etc/nginx/conf.d/default.conf ./default.conf vim ./default.conf#copy 下面的 server {listen 80;server_name localhost;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;location / {root /usr/share/nginx/html;index index.html index.htm index.php;}#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 172.17.0.2:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$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;#} } # 修改 fastcgi_pass 127.0.0.1:9000; 為: # fastcgi_pass 172.17.0.2:9000; # 其中 172.17.0.2 上面查看 IP 獲取的 每次都不一樣 #覆蓋到 nginx docker cp ./default.conf nginx:/etc/nginx/conf.d/default.conf #重啟 nginx docker restart nginx
  • 新建 /tmp/index.php
  • <?phpecho phpinfo();
  • 訪問本地 127.0.0.1 即可
  • docker 常用命令
  • 進入容器

    docker exec -it nginx /bin/bash

    復制容器內的配置到宿主機器

    docker cp nginx:/etc/nginx/conf.d/default.conf ./default.conf

    復制宿主機器文件到容器

    docker cp ./default.conf myNginx:/etc/nginx/conf.d/default.conf

    docker 重啟容器

    docker restart nginx

    停止所有容器

    docker stop $(docker ps -a -q)

    刪除所有容器

    docker rm $(docker ps -a -q)

    轉載于:https://www.cnblogs.com/wangmy/p/10441084.html

    總結

    以上是生活随笔為你收集整理的使用 docker 搭建 nginx+php-fpm 环境 (两个独立镜像)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。