基于Docker搭建 Php-fpm + Nginx 环境
2021/7/27 7:08:03
本文主要是介绍基于Docker搭建 Php-fpm + Nginx 环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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 环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善