Nginx 源码安装及php-fpm访问

环境:Ubuntu 16.04


1、Nginx源码下载
wget http://nginx.org
2、下载依赖模块pcre、openssl、zlib
2.1、pcre:http://www.pcre.org/
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
2.2、openssl:http://www.openssl.org/
wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz

2.3、zlib:http://zlib.net
wget:http://zlib.net/zlib-1.2.11.tar.gz

3、安装前配置
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/root/pcre-8.41 \
--with-zlib=/root/zlib-1.2.11 \
--with-openssl=/root/openssl-1.1.0g


4、编译和安装
make && make install


5、配置nginx通过fastcgi访问php-fpm
方法一:
server{
listen  80;
server_name test.com;
index index.php;
root /var/www/test/web;
#以fastcgi配置php-fpm
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;#php-fpm运行默认端口9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /var/log/test/access.log;
error_log  /var/log/test/error.log;
}


方法二:PHP-FPM使用Unix套接字,需要修改/usr/local/php/etc/php-fpm.d/www.conf
修改后如下:
[...]
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php7-fpm.sock
[...]


server{
listen  80;
server_name test.com;
index index.php;
root /var/www/test/web;


#以fastcgi配置php-fpm
location ~ .php$ {
fastcgi_pass unix:/var/run/php-fpm/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /var/log/test/access.log;
error_log  /var/log/test/error.log;
}


6、编写脚本,并加入到开机启动服务
6.1、在/etc/init.d中编写脚步nginx,内容如下
#!/bin/bash
### BEGIN INIT INFO
# Provides:		Nginx
# Required-Start:       $network $remote_fs $syslog
# Required-Stop:        $network $remote_fs $syslog
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Very secure Nginx HTTP server
# Description:		Nginx is a high-performance web and proxy server
### END INIT INFO


#注意:这里的三个变量需要根据具体的环境而做修改。
nginxd=/usr/local/nginx/nginx
nginx_config=/usr/local/nginx/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"


# Check that networking is up.
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ]  
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
  echo -n $"Stopping $prog: "
  $nginxd -s stop
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
# reload nginx service functions.
reload() {
  echo -n $"Reloading $prog: "
  kill -HUP `cat ${nginx_pid}`
  RETVAL=$?
  echo
}
# See how we were called.
case "$1" in
  start)
          start
          ;;
  stop)
          stop
          ;;
  reload)
          reload
          ;;
  restart)
          stop
          start
          ;;
  status)
          status $prog
          RETVAL=$?
          ;;
  *)
          echo $"Usage: $prog {start|stop|restart|reload|status|help}"
          exit 1
esac
exit $RETVAL




6.2、调整脚步权限
chmod 755 nginx


6.3、加入到开机启动服务
update-rc.d nginx defaults


6.4、管理开机启动服务
sysv-rc-conf


7、常用命令
service nginx start 启动
service nginx stop 停止
service nginx restart 重启
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值