ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

docker 安装 php +nginx 记录

2020-05-15 09:05:55  阅读:231  来源: 互联网

标签:www nginx html var docker php fastcgi


我的环境CentOS 7.5

首先安装 nginx

docker pull nginx
docker pull php:7.1.30-fpm

安装完成之后进行配置,首先要确定网站目录、nginx配置文件目录

mkdir /var/www
mkdir /etc/conf
cd /var/conf
vim test.conf

输入以下内容

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }

其中root   /usr/share/nginx/html 这个地方是指网站目录,要记住,挂载nginx目录时要用。fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name; 这个目录也很重要,挂载PHP目录的时候会用

启动php,挂载本地目录,注意,启动nginx也必须挂载这个目录:/var/www

docker run --name  myphp7 -v /var/www:/www -d php:7.1.30-fpm
docker run --name php-nginx -p 8800:80 -v /var/www:/usr/share/nginx/html -v /var/conf:/etc/nginx/conf.d -d --link myphp7:php nginx

启后后新建一个PHP测试一下:

cd /var/www
vim info.php

输入

<?php
    phpinfo();
?>

看看能否打开

curl localhost:8000/info.php

结果返回403 Forbidden

因为是CentOS7,尝试关闭SeLinux

vim /etc/selinux/config

SELINUX=disabled

保存重试,仍然返回403 Forbidden。尝试修改权限

chmod -R 777 /var/www/

OK!

标签:www,nginx,html,var,docker,php,fastcgi
来源: https://www.cnblogs.com/yesok/p/12892826.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有