Nginx的编译安装及服务启动脚本
1、解决依赖关系
编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries"。同时,还需要专门安装pcre-devel包:
# yum -y install pcre-devel
2.添加系统用户,实现与之运行nginx的服务进程
groupadd -r nginx
useradd -r -g nginx nginx
id nginx 查看新建的用户id
3.下载源码包上传编译安装 (www.nginx.org)
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre
make && make install
4.为nginx提供服务启动脚本
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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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
添加执行权限
chmod +x /etc/init.d/nginx
添加到服务管理列表,并让其开机自动启动:
chkconfig --add nginx
chkconfig nginx on
chkconfig --list nginx 查看添加情况
启动服务脚本
service nginx start
浏览访问此服务器ip的80端口即可
Nginx的编译安装及服务启动脚本的更多相关文章
- nginx的编译安装以及启动脚本编写
Nginx的编译安装和启动脚本的编写 Nginxd的功能强大,可以实现代理.负载均衡等企业常用的功能.下面介绍一下nginx的编译安装方法: 1. 下载 官方下载地址:http://nginx.org ...
- 【01】Nginx:编译安装/动态添加模块
写在前面的话 说起 Nginx,别说运维,就是很多开发人员也很熟悉,毕竟如今已经 2019 年了,Apache 更多的要么成为了历史,要么成为了历史残留. 我们在提及 Nginx 的时候,一直在强调他 ...
- Nginx 的编译安装和URL地址重写
本文转自:http://www.178linux.com/14119#rd?sukey=ecafc0a7cc4a741b573a095a3eb78af6b4c9116b74d0bbc9844d8fc5 ...
- Linux 通过编译安装apache服务以及配置
Linux 编译安装apache服务 一.安装 1.通过编译安装,首先需要下载源代码安装包 apache下载链接:http://httpd.apache.org/download.cgi 2.解开源代 ...
- 初识Nginx及编译安装Nginx
初识Nginx及编译安装Nginx 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...
- 自己编写服务启动脚本(一):functions文件详细分析和说明
本文目录: 1.几个显示函数2.action函数3.is_true和is_false函数4.confirm函数5.pid检测相关函数 5.1 checkpid.__pids_var_run和__pid ...
- nginx应用编译安装
nginx应用编译安装: 安装编译所需依赖包: # apt-get install make gcc g++ libcurl3-openssl-dev libfreetype6-dev libmcry ...
- centos6服务启动脚本及开机启动过程
centos6服务启动脚本 centos6的服务启动脚本都放在/etc/rc.d/init.d/下,/etc/init.d/是/etc/rc.d/init.d/的软链接: centos6的服务启动脚本 ...
- 解决mysql跟php不在同一台机器上,编译安装php服务报错问题:configure: error: Cannot find MySQL header files under /application/mysql.
在编译安装php服务时报错: configure: error: Cannot find MySQL header files under /application/mysql. Note that ...
随机推荐
- C++ 虚函数、纯虚函数、虚继承
1)C++利用虚函数来实现多态. 程序执行时的多态性通过虚函数体现,实现运行时多态性的机制称爲动态绑定:与编译时的多态性(通过函数重载.运算符重载体现,称爲静态绑定)相对应. 在成员函数的声明前加上v ...
- MVC分页技术
这个是用的插件分页技术 前台引用和js <script type="text/javascript" src="/js/jquery-1.10.2.min.js&q ...
- 从零开始的全栈工程师——js篇(作用域 this 原型笔试题练习)
作用域 // 1. fn() function fn () { console.log(12) } var as = function () { console.log(45) } // 2. var ...
- 关于基于Linphone的视频通话Android端开发过程中遇到的问题
关于基于Linphone的视频通话Android端开发过程中遇到的问题 运用开源项目Linphone的SDK进行开发,由于是小组进行开发,我主要负责的是界面部分. 由于当时是初学Android开发,对 ...
- Android Studio快捷键【Android学习入门】
Studio快捷键[Android学习入门]" title="Android Studio快捷键[Android学习入门]"> 提示 Ctrl+P方法参数提示 Ct ...
- centos7 mod_gearman 3.0.1 打包rpm
wget https://github.com/sni/mod_gearman/archive/v3.0.1.tar.gz -O /root/rpmbuild/SOURCES/mod_gearman- ...
- 笨办法学Python(二十七)
习题 27: 记住逻辑关系 到此为止你已经学会了读写文件,命令行处理,以及很多 Python 数学运算功能.今天,你将要开始学习逻辑了.你要学习的不是研究院里的高深逻辑理论,只是程序员每天都用到的让程 ...
- Java UUID Generator(JUG)
UG 是一个纯 Java 的 UUID 生成器. UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成UUID的API.UUID按照开放软件基金 会 (OS ...
- PHP获取系统时间不对的解决办法(转载)
原地址:https://blog.csdn.net/u012124764/article/details/51450958 使用PHP获取系统时间,发现时间不对,是因为PHP默认的时区是UTC,应该将 ...
- POJ-3111 K Best---二分求最大化平均值
题目链接: https://cn.vjudge.net/problem/POJ-3111 题目大意: 卖宝救夫:Demy要卖珠宝,n件分别价值vi 重 wi,她希望保留k件使得 最大. 解题思路: # ...