nginx1.12.2配置php,centos6.9编译安装nginx1.12.2

切换到root用户

sudo -i

创建站点目录

mkdir -p /www/wwwroot

进入下载文件的目录

cd /usr/local/src

下载文件

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz

wget http://cn2.php.net/distributions/php-7.2.0.tar.gz

wget https://nginx.org/download/nginx-1.12.2.tar.gz

解压压缩文件

tar zxvf nginx-1.12.2.tar.gz

安装相关依赖库(非常重要)

yum -y install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel openssl-perl openssl-static perl-ExtUtils-Embed libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data

创建Nginx用户和组

# 创建一个组

groupadd www

# 创建一个用户,不允许登陆和不创主目录

useradd -s /sbin/nologin -g www -M www

# 更改目录权限

chown www:www /www/wwwroot

chmod -R 755 /www/wwwroot

查看创建的账号

cat /etc/passwd

查看创建的目录

ls /www

去到nginx解压的目录进行编译

cd /usr/local/src/nginx-1.12.2

接下来执行预编译脚本,如下:

# 需要编译的功能模块如下

./configure \

--prefix=/usr/local/nginx \

--user=www \

--group=www \

--with-select_module \

--with-poll_module \

--with-http_ssl_module \

--with-http_v2_module \

--with-http_stub_status_module \

--with-http_perl_module \

--with-http_gzip_static_module \

--with-http_gunzip_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_xslt_module \

--with-http_image_filter_module \

--with-http_sub_module \

--with-http_flv_module \

--with-http_mp4_module \

--with-http_random_index_module \

--with-http_secure_link_module \

--with-http_slice_module \

--with-http_auth_request_module \

--with-http_degradation_module \

--with-stream \

--with-stream_ssl_module \

--with-stream_ssl_module \

--with-stream_realip_module \

--with-stream_geoip_module \

--with-pcre \

--with-pcre-jit \

--with-mail \

--with-mail_ssl_module \

--with-threads \

--with-compat

再次执行

make && make install

查看安装目录文件

ls /usr/local/nginx

如下:

conf html logs sbin

查看是否安装完成

/usr/local/nginx/sbin/nginx -t

如下:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

添加启动脚本

vim /etc/init.d/nginx

脚本内容如下:

#!/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)

sysconfig="/etc/sysconfig/$prog"

lockfile="/var/lock/subsys/nginx"

pidfile="/usr/local/nginx/logs/${prog}.pid"

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f $sysconfig ] && . $sysconfig

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 -p $pidfile $prog

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest_q || return 6

stop

start

}

reload() {

configtest_q || return 6

echo -n $"Reloading $prog: "

killproc -p $pidfile $prog -HUP

echo

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

configtest_q() {

$nginx -t -q -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

# Upgrade the binary with no downtime.

upgrade() {

local oldbin_pidfile="${pidfile}.oldbin"

configtest_q || return 6

echo -n $"Upgrading $prog: "

killproc -p $pidfile $prog -USR2

retval=$?

sleep 1

if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then

killproc -p $oldbin_pidfile $prog -QUIT

success $"$prog online upgrade"

echo

return 0

else

failure $"$prog online upgrade"

echo

return 1

fi

}

# Tell nginx to reopen logs

reopen_logs() {

configtest_q || return 6

echo -n $"Reopening $prog logs: "

killproc -p $pidfile $prog -USR1

retval=$?

echo

return $retval

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest|reopen_logs)

$1

;;

force-reload|upgrade)

rh_status_q || exit 7

upgrade

;;

reload)

rh_status_q || exit 7

$1

;;

status|status_q)

rh_$1

;;

condrestart|try-restart)

rh_status_q || exit 7

restart

;;

*)

echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"

exit 2

esac

附nginx脚本介绍

nginx启动脚本

添加自启动权限,启动服务

#附加执行权限

chmod +x /etc/init.d/nginx

#开机自启

chkconfig --add nginx

chkconfig nginx on

#启动服务

/etc/init.d/nginx start

#其他相对应的服务命令(可选 )

# (start | stop | restart | reload | status | help)

service nginx restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值