文章转自:https://typecodes.com/web/centos7compilenginx.html
如果编译出错查看:https://typecodes.com/web/solvenginxcompileerror.html
1 依赖库配置,编译和安装Nginx1.9.0
先创建一个名为nginx且没有登录权限的用户和一个名为nginx的用户组,然后安装nginx所需的依赖库和依赖包,最后通过.configure进行安装的详细配置。另外,补录一个pcre的tar包备份地址:https://dn-vfhky.qbox.me/libs/nginx/pcre-8.36.tar.gz,以及一个zlib的tar包备份地址:https://dn-vfhky.qbox.me/libs/nginx/zlib-1.2.8.tar.gz。
#######新建nginx用户和nginx组
[root@typecodes ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx
#######yum安装nginx必须的依赖库
[root@typecodes ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed
#######官网下载Nginx1.9.0的tar包,然后解压到服务器上
[root@typecodes ~]# wget -c http://nginx.org/download/nginx-1.9.0.tar.gz
[root@typecodes ~]# tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0
#######下载pcre的tar包并解压,以便支持Nginx的Rewrite功能
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/php/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz
#######下载zlib的tar包并解压,以便支持Nginx的Gzip压缩功能
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/nginx/zlib-1.2.8.tar.gz
[root@typecodes nginx-1.9.0]# tar -zxf zlib-1.2.8.tar.gz
#######新建Nginx1.9.0安装时所需要的目录
[root@typecodes nginx-1.9.0]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[root@typecodes tmp]# mkdir -p /var/run/nginx && cd ~/nginx-1.9.0
准备工作做好后,就开始正式配置Nginx-1.9.0的安装明细了。注意,在使用下面这条configure参数配置时,一定要先把反斜杠“\”后面添加的注释文字去掉!!!
[root@typecodes nginx-1.9.0]# ./configure \
--prefix=/usr/share/nginx \ [Nginx安装目录]
--sbin-path=/usr/sbin/nginx \ [Nginx的sbin目录]
--conf-path=/etc/nginx/nginx.conf \ [Nginx的配置文件]
--error-log-path=/var/log/nginx/error.log \ [Nginx的错误日志]
--http-log-path=/var/log/nginx/access.log \ [Nginx的访问日志]
--pid-path=/var/run/nginx/nginx.pid \ [Nginx的进程ID]
--lock-path=/var/lock/nginx.lock \
--user=nginx \ [Nginx所属用户]
--group=nginx \ [Nginx所属用户组]
--with-http_ssl_module \ [Nginx的ssl模块]
--with-http_spdy_module \ [Nginx的Google spdy模块]
--with-http_dav_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_random_index_module \
--with-http_degradation_module \
--with-http_secure_link_module \
--with-http_gzip_static_module \ [Nginx的gzip压缩模块]
--with-http_perl_module \
--with-pcre=pcre-8.36 \ [pcre的安装目录]
--with-zlib=zlib-1.2.8 \ [pcre的安装目录]
--with-debug \ [允许DEBUG]
--with-file-aio \
--with-mail \
--with-mail_ssl_module \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-stream \ [Nginx1.9.0特有的stream模块]
--with-ld-opt="-Wl,-E" [gcc的编译优化]
备注:以下为已经格式化好的数据,直接复制即可
可能遇到问题:./configure: error: perl module ExtUtils::Embed is required
问题描述:缺少这个模块,需要yum安装以下即可
解决办法:yum install perl perl-devel perl-ExtUtils-Embed
./configure --prefix=/usr/share/nginx --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_spdy_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module
--with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_perl_module --with-pcre=pcre-8.36 --with-zlib=zlib-1.2.8 --with-debug --with-file-aio --with-mail --with-mail_ssl_module --http-client-body-temp-path=/var/tmp/nginx/client_body
--http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-ld-opt="-Wl,-E"
配置过程大概需要5分钟左右
2 配置完后,就可以直接编译和安装了
最后,直接使用执行这条命令[root@typecodes nginx-1.9.0]# make && make install进行安装即可。
[root@typecodes nginx-1.9.0]# make && make install
3 配置Nginx1.9.0,使之正常工作
成功安装Nginx1.9.0后,我们需要进行一些配置,包括开机启动、SSL/HTTPS服务等。其中,Nginx服务控制脚本nginx见文章《Nginx服务启动、停止和重启等操作的SHELL脚本》。
https://typecodes.com/web/nginxserviceoptshell.html
#######上传Nginx服务控制脚本nginx,并赋予执行权限,删除安装包,添加Nginx服务到开机启动
这一步可能会出现没有nginx服务脚本,自行下载一个,或者把下面的复制,然后文件名为nginx
#文件开始
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemin
#
# 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
# 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_C/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
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 $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
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
#文件结束
[root@typecodes ~]# mv ~/nginx /etc/init.d/nginx && chmod +x /etc/init.d/nginx
如果/etc/init.d/nginx存在,不要覆盖,直接执行 chmod +x /etc/init.d/nginx
[root@typecodes ~]# rm -rf nginx-1.9.0*
[root@typecodes ~]# chkconfig --add nginx
[root@typecodes ~]# chkconfig nginx on
#######测试配置是否正常
root@typecodes ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#######新建Nginx进程日志nginx.pid目录,并启动服务
加上这个mkdir就能够兼容服务器重启这种情况了
[root@typecodes ~]# mkdir -p /var/run/nginx/
[root@typecodes ~]# service nginx start
以上就介绍了CentOS 71编译安装nginx,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

在PHP中,trait适用于需要方法复用但不适合使用继承的情况。1)trait允许在类中复用方法,避免多重继承复杂性。2)使用trait时需注意方法冲突,可通过insteadof和as关键字解决。3)应避免过度使用trait,保持其单一职责,以优化性能和提高代码可维护性。

依赖注入容器(DIC)是一种管理和提供对象依赖关系的工具,用于PHP项目中。DIC的主要好处包括:1.解耦,使组件独立,代码易维护和测试;2.灵活性,易替换或修改依赖关系;3.可测试性,方便注入mock对象进行单元测试。

SplFixedArray在PHP中是一种固定大小的数组,适用于需要高性能和低内存使用量的场景。1)它在创建时需指定大小,避免动态调整带来的开销。2)基于C语言数组,直接操作内存,访问速度快。3)适合大规模数据处理和内存敏感环境,但需谨慎使用,因其大小固定。

PHP通过$\_FILES变量处理文件上传,确保安全性的方法包括:1.检查上传错误,2.验证文件类型和大小,3.防止文件覆盖,4.移动文件到永久存储位置。

JavaScript中处理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。1.??返回第一个非null或非undefined的操作数。2.??=将变量赋值为右操作数的值,但前提是该变量为null或undefined。这些操作符简化了代码逻辑,提高了可读性和性能。

CSP重要因为它能防范XSS攻击和限制资源加载,提升网站安全性。1.CSP是HTTP响应头的一部分,通过严格策略限制恶意行为。2.基本用法是只允许从同源加载资源。3.高级用法可设置更细粒度的策略,如允许特定域名加载脚本和样式。4.使用Content-Security-Policy-Report-Only头部可调试和优化CSP策略。

HTTP请求方法包括GET、POST、PUT和DELETE,分别用于获取、提交、更新和删除资源。1.GET方法用于获取资源,适用于读取操作。2.POST方法用于提交数据,常用于创建新资源。3.PUT方法用于更新资源,适用于完整更新。4.DELETE方法用于删除资源,适用于删除操作。

HTTPS是一种在HTTP基础上增加安全层的协议,主要通过加密数据保护用户隐私和数据安全。其工作原理包括TLS握手、证书验证和加密通信。实现HTTPS时需注意证书管理、性能影响和混合内容问题。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版
中文版,非常好用

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。