爱快docker安装PHP和Nginx
本文章参考连接:Docker 安装 PHP | 菜鸟教程
安装PHP
1、搜索并下载PHP镜像
搜索一个带-fpm的php镜像并下载
2、创建PHP容器
安装Nginx
1、下载Nginx镜像
2、创建Nginx容器
配置Nginx
1、配置default.conf
进入存有default.conf的目录
root@nginx:/# cd /etc/nginx/conf.d/
root@nginx:/etc/nginx/conf.d# ls
default.conf
root@nginx:/etc/nginx/conf.d#
备份原有配置
root@nginx:/etc/nginx/conf.d# cp default.conf default.conf.bak
root@nginx:/etc/nginx/conf.d#
查看原有配置
root@nginx:/etc/nginx/conf.d# cat default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index 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 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
root@nginx:/etc/nginx/conf.d#
将配置内容复制到本地并修改
将修改好的文件上传到本地址映射文件夹
root@nginx:/etc/nginx/conf.d# cd /usr/share/nginx/html
root@nginx:/usr/share/nginx/html# ls
default.conf hosts index.css index.html index.php
将 default.conf 文件复制到原来的位置
root@nginx:/usr/share/nginx/html# cp ./default.conf /etc/nginx/conf.d/
root@nginx:/usr/share/nginx/html# cd /etc/nginx/conf.d/
root@nginx:/etc/nginx/conf.d# ls
default.conf default.conf.bak
root@nginx:/etc/nginx/conf.d# cat default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index 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 192.168.8.3:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/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;
#}
}
root@nginx:/etc/nginx/conf.d#
2、配置hosts
找到对应目录
root@nginx:/etc/nginx/conf.d# cd /etc/
root@nginx:/etc# ls
adduser.conf ca-certificates.conf deluser.conf gai.conf host.conf issue.net localtime netconfig pam.d rc1.d rcS.d shadow- systemd
alternatives cron.d dpkg group hostname kernel login.defs nginx passwd rc2.d resolv.conf shells terminfo
apt cron.daily e2scrub.conf group- hosts ld.so.cache logrotate.d nsswitch.conf passwd- rc3.d rmt skel timezone
bash.bashrc debconf.conf environment gshadow init.d ld.so.conf mke2fs.conf opt profile rc4.d security ssl ucf.conf
bindresvport.blacklist debian_version fonts gshadow- inputrc ld.so.conf.d motd os-release profile.d rc5.d selinux subgid update-motd.d
ca-certificates default fstab gss issue libaudit.conf mtab pam.conf rc0.d rc6.d shadow subuid xattr.conf
root@nginx:/etc#
将hosts配置复制到本地进行修改
root@nginx:/etc# cat hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.8.2 nginx
root@nginx:/etc#
将修改的hosts复制到它容器中原来的位置
root@nginx:/etc# ls
adduser.conf ca-certificates.conf deluser.conf gai.conf host.conf issue.net localtime netconfig pam.d rc1.d rcS.d shadow- systemd
alternatives cron.d dpkg group hostname kernel login.defs nginx passwd rc2.d resolv.conf shells terminfo
apt cron.daily e2scrub.conf group- hosts ld.so.cache logrotate.d nsswitch.conf passwd- rc3.d rmt skel timezone
bash.bashrc debconf.conf environment gshadow init.d ld.so.conf mke2fs.conf opt profile rc4.d security ssl ucf.conf
bindresvport.blacklist debian_version fonts gshadow- inputrc ld.so.conf.d motd os-release profile.d rc5.d selinux subgid update-motd.d
ca-certificates default fstab gss issue libaudit.conf mtab pam.conf rc0.d rc6.d shadow subuid xattr.conf
root@nginx:/etc# cp /usr/share/nginx/html/hosts ./
root@nginx:/etc# cat hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.8.3 php
root@nginx:/etc#
测试
创建php文件
放到本地挂载的目录中
得到
来源地址:https://blog.csdn.net/weixin_43788435/article/details/126449806
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341