Centos7.2安装Nginx
我的系统是Centos7.2 64位,首先yum update
编译安装Nginx
yum update
安装缺少的依赖包
yum -y install gcc gcc-c++ make automake autoconf libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
在这里下载nginxwen'd'ban,下载的文件放在 /usr/local
解压,cd
进入解压后的文件夹,执行
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
make -j 128 && make install
常用编译选项说明在 这里
关于yum
安装与源码
安装的不同,请见这里
启动/停止nginx
/usr/local/nginx/sbin/nginx #启动nginx
/usr/local/nginx/sbin/nginx -s stop #停止nginx
启动 nginx
服务后,可以通过 ps -aux | grep nginx
查看进程
开机启动
注:参考自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/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
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
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
fi
}
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
EricHu的专栏
开发中遇到的坑
7 声望
0 粉丝
推荐阅读
Bash 常用脚本片段
这段脚本非常有用,你只要在你的脚本开头加上下面的内容,就能以 --param value 的格式解析参数。由于这段脚本尽可能写的短小不占空间,所以格式方面会要求所有的参数都有值,例如不接受无参数的 --daemon,而必...
捏造的信仰赞 5阅读 1.7k评论 1
CentOS从零开始部署Nodejs项目
原文地址:[链接]安装nodejs、npm/cnpm {代码...} 安装mysql卸载 {代码...} 安装 {代码...} 启动 {代码...} 登录 {代码...} 修改root密码 {代码...} 允许远程访问,与本地密码区分,是两个密码 {代码...} 安装git...
jigsaw赞 3阅读 5k评论 3
Nginx 配置常用参数,看这一篇就够了
最近在全面学习Nginx,当作笔记了,如有错误,欢迎指出或深入交流。主模块 {代码...} 事件模块 {代码...} http部分 {代码...} 部分参数详细说明server_name {代码...} location {代码...} location表达式类型 {代...
13sai赞 2阅读 1.8k
把 Go 放到 Nginx C module 之中
最近一段时间,我在做一件有趣的事情,让一个 Nginx C module 通过 Go 代码来访问 gRPC 服务。不得不感慨 Go 真的很流行,让人无法拒绝。之前我做 wasm-nginx-module 时就试图把 tinygo 跑在 Nginx 里面,这次则...
spacewander赞 2阅读 2.1k评论 2
化虹为桥 - Nginx 如何代理 UDP “连接”
众所周知,UDP 并不像 TCP 那样是基于连接的。但有些时候,我们需要往一个固定的地址发送多个 UDP 来完成一个 UDP 请求。为了保证服务端能够知道这几个 UDP 包构成同一个会话,我们需要在发送 UDP 包时绑定某个端...
spacewander赞 4阅读 1k
nginx配置ssl证书
{代码...}
eyuxiog赞 1阅读 1.4k
Nginx unexpected end of file 配置证书遇到问题,如何解决?
通过 letsencrypt 申请证书后,默认服务器安装了 Nginx 1.8 发现,在默认的 /etc/nginx/sites-enabled/default 内容配置 SSL 的 site.com.key 后。重启 Nginx 出现一下错误:
程序员泥瓦匠赞 1阅读 378
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。