標簽: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
標簽:doc page ref restart 編寫 掛載 targe oca static
原文地址:https://www.cnblogs.com/GetcharZp/p/15062691.html