碼迷,mamicode.com
首頁 > Web開發 > 詳細

基于Docker搭建 Php-fpm + Nginx 環境

時間:2021-07-27 17:31:51      閱讀:0      評論:0      收藏:0      [點我收藏+]

標簽:doc   page   ref   restart   編寫   掛載   targe   oca   static   

1、拉取nginx鏡像,以及php-fpm鏡像

docker pull nginx:1.16.0
docker pull php:5.6.40-fpm

2、分別創建nginx 容器php-fpm 容器

# 這里最后吧 /etc/nginx/conf.d 目錄和存放靜態資源文件的目錄掛載到宿主機上來
docker run -d --name nginx_1_16_0 --link php_fpm_5_6_40:php_fpm_5_6_40 nginx:1.16.0

# 這里可以把 存儲代碼的目錄也掛載到宿主機上
docker run -d --name php_fpm_5_6_40 php:5.6.40-fpm

3、參考下例編寫 nginx 配置文件

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /var/www/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   /var/www/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           /var/www/html; # php-fpm 容器代碼存放路徑
        fastcgi_pass   php_fpm_5_6_40:9000; # php_fpm_5_6_40 是啟動nginx時候link參數第二個值
        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;
    }
}

4、重啟nginx容器

docker restart <容器ID>

參考鏈接:

https://blog.csdn.net/qq_35765928/article/details/87715448

https://blog.csdn.net/qq_38711879/article/details/105407750

基于Docker搭建 Php-fpm + Nginx 環境

標簽:doc   page   ref   restart   編寫   掛載   targe   oca   static   

原文地址:https://www.cnblogs.com/GetcharZp/p/15062691.html

(0)
(0)
   
舉報
評論 一句話評論(0
登錄后才能評論!
? 2014 mamicode.com 版權所有  聯系我們:gaon5@hotmail.com
迷上了代碼!
4399在线看MV_久久99精品久久久久久久久久_成人又黄又爽又刺激视频_能收黄台的app不收费