CentOS 7 源码编译安装 Nginx
这里安装的是nginx 1.14版本
1.下载源码
#下载
wget http://nginx.org/download/nginx-1.14.0.tar.gz
#解压
tar -xzf nginx-1.14.0.tar.gz
cd nginx-1.14.0
2.安装编译环境
yum update
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
3.编译安装
#添加用户和组
groupadd www
useradd -g www www#配置
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-threads#编译
make#安装
make install
4.验证
/usr/local/nginx/sbin/nginx -V
输出如下:
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads
5.创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
6.开机自启动
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: /usr/local/nginx/conf/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /usr/local/nginx/logs/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 directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`if [ -z "`grep $user /etc/passwd`" ]; thenuseradd -M -s /bin/nologin $userfioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d "=" -f 2`if [ ! -d "$value" ]; then# echo "creating" $valuemkdir -p $value && chown -R $user $valuefifidone
}
start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval
}
stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval
}
restart() {configtest || return $?stopsleep 1start
}
reload() {configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?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" instart)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 a+x /etc/init.d/nginx
将nginx服务加入chkconfig管理列表
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
# 启动
systemctl start nginx
7.测试
curl localhost:80
会有如下输出
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
8.配置优化
下列配置在nginx.conf里与http节点同级
cd /usr/local/nginx/conf
vim nginx.conf
user www www;
worker_processes auto;
worker_rlimit_nofile 51200;events{use epoll;worker_connections 51200;multi_accept on;}
http节点下加入下列配置,将会从指定目录加载配置文件
include /etc/nginx/*.conf;
9.常用命令
# 启动
systemctl start nginx
# 查看状态
systemctl status nginx
# 停止
systemctl stop nginx# 重载配置
nginx -s reload
# 测试配置是否正确
nginx -t
参考资料
https://www.cnblogs.com/visec479/p/5145624.html
https://www.cnblogs.com/whatmiss/p/7091220.html
CentOS 7 源码编译安装 Nginx相关推荐
- Centos 7 源码编译安装 mysql
文章目录 Centos 7 源码编译安装 mysql 1. 卸载 centos 自带的 mariadb 2. 下载 mysql 3. 安装 mysql 3.1 解压压缩包 3.1.1 自定义解压安装目 ...
- 源码编译安装Nginx及网站服务配置
文章目录 一.Nginx概述 1.1 Nginx概述 1.2 Nginx和Apache的区别 1.3Nginx和Apache的优缺点差异 1.4Nginx的进程 二.源码编译安装nginx服务 2.1 ...
- Ubuntu 16.04源码编译安装nginx 1.10.0
一.下载相关的依赖库 pcre 下载地址 http://120.52.73.43/jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.t ...
- ClickHouse系列教程七:centos下源码编译安装及报错解决
ClickHouse系列教程: ClickHouse系列教程 参考上一篇博客: ClickHouse系列教程六:源码分析之Debug编译运行 先安装 gcc 8, g++ 8, cmake 3, ni ...
- linux安装nginx源码,CentOS7源码编译安装Nginx
一.安装步骤 1.下载 nginx 源码包 官网$ wget http://nginx.org/download/nginx-1.16.0.tar.gz 2.解压 nginx 压缩包$ tar -zx ...
- Linux 利用nginx源码编译安装nginx
环境 1, CentOS 7 2, nginx 1.13.6 步骤 1,编译前准备 yum install pcre* openssl openssl-devel zlib zlib-devel 2, ...
- linux源码编译安装nginx
1.从nginx的官方网站下载nginx的安装源码包,要下载.gz格式的包才是linux安装包 网址http://nginx.org/download/ wget http://nginx.org/d ...
- 源码编译安装Nginx
1.源码下载 Nginx在github上有一个只读源码库,我获取的源码方式为: git clone https://github.com/nginx/nginx.git 2.configure 我下载 ...
- Linux /centos7源码编译安装Nginx
1.下载或上传nginx安装包 我这边使用wget命令直接在centos7上下载,上传安装包的可以忽略直接下一步 [root@localhost ~]# wget http://nginx.org/d ...
最新文章
- docker基础文档(链接,下载,安装)
- 没错,使用 Nacos 踩坑了
- Linux 学习日记 2: 目录结构和文件操作
- Flex很可能会消失
- LinuxMint 14 更新源(能成功的!)
- Windows下Go语言的安装和运行
- 16s及宏基因组测序公司资源--20161104
- vim编写python没有代码提示_vim编写python自动补全
- [转]你所不知的 CSS ::before 和 ::after 伪元素用法
- 程序实现php文件上传,PHP实例:实现文件上传的程序源码_php
- 解决navicat连接不上mysql8
- ModuleNotFoundError: No module named 'tornado'解决办法
- macbook查看java版本,Mac下查看JDK版本和安装目录
- 香农编码,哈夫曼编码与费诺编码的比较
- qt5 开发及实例(第4版)_张厚粲现代心理与教育统计学第4版配套章节题库
- Win32多语言IME应用程序编程接口(API)
- 2019.1.21【NOIP提高组】模拟B组 JZOJ 4208 线段树什么的最讨厌了
- matlab 切比雪夫距离,matlab中用pdist函数计算切比雪夫chebychev距离的计算顺序
- postgresql 执行sql文件
- Unity(8)-开启或关闭背景音乐