首先创建一个放置docker映射nginx容器和php容器得文件夹
docker pull nginx:1.18.0
mkdir -p /home/admin/nginx/conf
mkdir -p /home/admin/nginx/log
mkdir -p /home/admin/nginx/www
docker run -d --name nginxtest nginx
docker cp nginxtest:/etc/nginx /home/admin/nginx/conf
docker cp nginxtest:/var/log /home/admin/nginx/log
docker cp nginxtest:/usr/share/nginx/www /home/admin/nmp/www
docker rm -f nginxtest
[root@localhost ~]# tree nginx
nginx
├── conf.d
│ └── default.conf
├── fastcgi_params
├── mime.types
├── modules -> /usr/lib/nginx/modules
├── nginx.conf
├── scgi_params
└── uwsgi_params
[root@localhost ~]# tree log
log
├── apt
│ ├── eipp.log.xz
│ ├── history.log
│ └── term.log
├── btmp
├── dpkg.log
├── faillog
├── lastlog
├── nginx
│ ├── access.log -> /dev/stdout
│ └── error.log -> /dev/stderr
└── wtmp
docker pull php:7.4.28-fpm
docker images
docker run -d --name phptest php:7.4.28-fpm
docker cp phptest:/usr/local/etc/php /home/admin/nmp/php
docker rm -f phptest
[root@localhost ~]# tree php
php
├── conf.d
│ └── docker-php-ext-sodium.ini
├── php.ini-development(改名php.ini)
└── php.ini-production
docker pull mysql:5.7
#先运行一个测试mysql容器或者直接创建把容器里的mysql目录复制出来
docker cp mysqltest:/var/log/mysql /home/admin/nmp/mysql/log
docker cp mysqltest:/var/lib/mysql /home/admin/nmp/mysql/data
docker cp mysqltest:/etc/mysql /home/admin/nmp/mysql/conf
docker inspect 容器ID
docker run -p 80:80 -d --name nginx1180 -v /home/admin/nmp/www:/usr/share/nginx/www -v /home/admin/nmp/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /home/admin/nmp/log:/var/log/nginx c2c45d506085;
docker run -p 9000:9000 -d --name php74 -v /home/admin/nmp/www:/usr/share/nginx/www -v /home/admin/nmp/php/conf.d/php.ini:/usr/local/etc/php/php.ini 08ccd6665390
docker run -p 3306:3306 -d --name mysql57 --restart unless-stopped -v /home/admin/nmp/mysql/log:/var/log/mysql -v /home/admin/nmp/mysql/data:/var/lib/mysql -v /home/admin/nmp/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 3147495b3a5c
由于在docker容器内转发php所以要使用php容得IP进行转发 nginx conf.d default.conf相关配置
server {
listen 80;
server_name zxft.daiying.net.cn;
index index.php index.html index.htm default.php default.htm default.html;
root /usr/share/nginx/www/public;
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
#autoindex on;
}
location ~ \.php(.*)$ {
#这里的ip 通过 docker inspect php容器ID 查看 ipAddress
fastcgi_pass 172.17.0.2:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log off;
}
}
location ~ ^/ {
proxy_pass http://10.4.123.99:80;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_read_timeout 120s;
}
本文为会飞的鱼原创文章,转载无需和我联系,但请注明来自会飞的鱼博客https://php.daiying.net.cn
最新评论