分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

CentOS7 配置 nginx php php-fpm

发布时间:2023-09-06 01:14责任编辑:赖小花关键词:配置nginx

上一篇说到安装 php

 装完并没有任何设置,这篇记录一下设置。先设置 nginx 吧,nginx 网上多如繁星的设置但大都比较简单,属于基础设置,因此此处只贴出设置后的结果,用红色框表示一些自己改动或需要注意的地方

nginx 的基础设置很简单,设置个三次以上都能直接记住了。自己配置了一下 关于400、500系列错误的默认显示路径,404、403错误都显示 40x.html,500 的几个错误都显示 50x.html 错误,这样页面就能自己定义了。比如现在 404 就会显示这样一个页面

启动 nginx遇到了插曲

因为是编译安装,因此安装后是这样启动的

cd /usr/local/nginxsudo ./nginx

今天在写配置时发现网上神句无法启动

sudo systemctl start nginx

百度大法让写一个脚本,好吧,写,打开 vim

#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: ??- 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # ??????????????proxy and IMAP/POP3 proxy server # processname: nginx # config: ?????/etc/nginx/nginx.conf # config: ?????/etc/sysconfig/nginx # pidfile: ????/var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { ????[ -x $nginx ] || exit 5 ????[ -f $NGINX_CONF_FILE ] || exit 6 ????echo -n $"Starting $prog: " ????daemon $nginx -c $NGINX_CONF_FILE ????retval=$? ????echo ????[ $retval -eq 0 ] && touch $lockfile ????return $retval } stop() { ????echo -n $"Stopping $prog: " ????killproc $prog -QUIT ????retval=$? ????echo ????[ $retval -eq 0 ] && rm -f $lockfile ????return $retval killall -9 nginx } restart() { ????configtest || return $? ????stop ????sleep 1 ????start } reload() { ????configtest || return $? ????echo -n $"Reloading $prog: " ????killproc $nginx -HUP RETVAL=$? ????echo } force_reload() { ????restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { ????status $prog } rh_status_q() { ????rh_status >/dev/null 2>&1 } case "$1" in ????start) ????????rh_status_q && exit 0 ????$1 ????????;; ????stop) ????????rh_status_q || exit 0 ????????$1 ????????;; ????restart|configtest) ????????$1 ????????;; ????reload) ????????rh_status_q || exit 7 ????????$1 ????????;; ????force-reload) ????????force_reload ????????;; ????status) ????????rh_status ????????;; ????condrestart|try-restart) ????????rh_status_q || exit 0 ????????????;; ????*) ?????????echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" ????????exit 2 esac ?#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: ??- 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # ??????????????proxy and IMAP/POP3 proxy server # processname: nginx # config: ?????/etc/nginx/nginx.conf # config: ?????/etc/sysconfig/nginx # pidfile: ????/var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { ????[ -x $nginx ] || exit 5 ????[ -f $NGINX_CONF_FILE ] || exit 6 ????echo -n $"Starting $prog: " ????daemon $nginx -c $NGINX_CONF_FILE ????retval=$? ????echo ????[ $retval -eq 0 ] && touch $lockfile ????return $retval } stop() { ????echo -n $"Stopping $prog: " ????killproc $prog -QUIT ????retval=$? ????echo ????[ $retval -eq 0 ] && rm -f $lockfile ????return $retval killall -9 nginx } restart() { ????configtest || return $? ????stop ????sleep 1 ????start } reload() { ????configtest || return $? ????echo -n $"Reloading $prog: " ????killproc $nginx -HUP RETVAL=$? ????echo } force_reload() { ????restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { ????status $prog } rh_status_q() { ????rh_status >/dev/null 2>&1 } case "$1" in ????start) ????????rh_status_q && exit 0 ????$1 ????????;; ????stop) ????????rh_status_q || exit 0 ????????$1 ????????;; ????restart|configtest) ????????$1 ????????;; ????reload) ????????rh_status_q || exit 7 ????????$1 ????????;; ????force-reload) ????????force_reload ????????;; ????status) ????????rh_status ????????;; ????condrestart|try-restart) ????????rh_status_q || exit 0 ????????????;; ????*) ?????????echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" ????????exit 2 esac ?

然后执行

:w /etc/init.d/nginx:qsudo chmod 755 /etc/init.d/nginxsudo chkconfig --add nginx

完成后,可以用以下命令对 nginx 进行操作(还有插曲)

#启动 nginx 服务sudo service nginx start#停止 nginx 服务sudo service nginx stop#无间断服务重启sudo service nginx reload

我要描述的插曲就是 脚本编辑完之后,用命令似乎无法停止 nginx,执行完命令依旧可以浏览,可以通过 sudo kill -quit nginx 这样的形式关停

先往下继续吧,安装 php-fpm 组件

sudo yum install php-fpm

编辑一下 /etc/php.ini (吐槽下 linux 下的配置文件在这个位置?)

#自愿是否先备份一下sudo cp /etc/php.ini /etc/php.ini.backupsudo vim /etc/php.ini/cgi.fix_pathinfo找到后去掉前面的分号 ;
:wq

配置 www.conf

#自愿备份一下 www.confsudo cp /etc/php.fpm.d/www.conf /etc/php-fpm.d/www.conf.backupsudo vim /etc/php.fpm.d/www.conf#将 user = xxxx 改为 user = 已经存在的有权限的用户#将 grouip = xxx 改为 group = 已经存在的有权限的组#以上两句是百度出来的,在虚拟机上我改为了当前用户名

依次启动 php-fpm 和 (重)启动 nginx

sudo systemctl start php-fpm#设置php-fpm开机启动#sudo systemctl enable php-fpmsudo systemctl restart nginx

这里的插曲在于我用 kill -quit nginx 退出之后再用 service start nginx 时遇到了错误提示

然后用 systemctl start nginx 启动了,但一会儿也会出现提示

暂时还不明所以,但 php 可以运行了

一些记录和链接:

  • 参考《nginx启动失败Failed to reload nginx.service: Unit not found》:http://blog.csdn.net/wangjinbao5566/article/details/72938783
  • 参考《centos下配置nginx支持php》:http://www.cnblogs.com/mitang/p/5524540.html
  • 参考《centos7安装并配置nginx+php》:http://www.cnblogs.com/cglWorkBook/p/5431571.html
  • 参考《如何正确配置 Nginx 和 PHP》:http://blog.jobbole.com/50121/

CentOS7 配置 nginx php php-fpm

原文地址:http://www.cnblogs.com/cinlap/p/7610133.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved