Nginx-源码编译安装

Nginx ("engine x") 是一个高性能的 HTTP和反向代理服务器。Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,Nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上Nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用Nginx网站用户有:百度BWS、新浪、网易、腾讯、等。


在Nginx官方下载网站即可下载程序包:www.nginx.org

Mainline version 主线版本
Stable version 稳定版本
Legacy versions 老版本,遗产版本
旧版本下载:http://mirrors.sohu.com/nginx/
Nginx 中文参考地址: http://www.nginx.cn/doc/
Apache的libphp5.so随着Apache服务器一起运行,而Nginx和php-fpm是各自独立运行,所以在运行过程中,Nginx和php-fpm都需要分别启动!
修改Nginx配置文件,启动Nginx服务,修改php配置文件,启动php-fpm服务

Nginx相对于Apache的优点:
轻量级,同样是 web 服务,比Apache 占用更少的内存及资源 ;高并发,Nginx 处理请求是异步非塞的,而Apache 则是阻塞型的,在高并发下Nginx 能保持低资源低消耗高性能;高度模块化的设计
编写模块相对简单;社区活跃,各种高性能模块出品迅速。


Apache 相对于Nginx 的优点:
rewrite,比Nginx 的rewrite强大;模块超多,基本想到的都可以找到;少bug ,Nginx 的bug 相对较多;超稳定
存在就是理由,一般来说,需要性能的web 服务,用Nginx 。如果不需要性能只求稳定,那就Apache。Nginx处理动态请求是弱项,一般动态请求要Apache去做,Nginx只适合静态和反向。

 

 

 

最小化安装centos 7.5,下yum源文件
1、wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo     阿里yum源
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo  163yum源
2、yum install vim net-tools ntpdate  lrzsz -y                                      

同步阿里时间
ntpdate ntp1.aliyun.com

安装nginx
1安装epel扩展yum源
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum clean all
yum list

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*
tar xf pcre-8.41.tar.gz -C /usr/local/src/
tar -zxvf nginx-1.15.12.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.15.12
useradd -M -s /sbin/nologin nginx

./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx

make -j 4 && make install


6. 配置Nginx支持php文件

cp /usr/local/nginx/conf/nginx.conf{,.bak}
vim /usr/local/nginx/conf/nginx.conf
改:2 #user nobody;
为:3 user nginx;
第66行始 修改为:
66 location ~ \.php$ {
67 root html;
68 fastcgi_pass 127.0.0.1:9000;
69 fastcgi_index index.php;
70 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
71 include fastcgi_params;
72 }

7. 启动Nginx服务
[root@xuegod63 nginx-1.14.1]# /usr/local/nginx/sbin/nginx


cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/


添加环境变量
[root@cga25 nginx-1.15.12]vim /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
9. 读取变量:
[root@xuegod63 nginx-1.14.1]# . /etc/profile.d/nginx.sh
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
10. 生成服务启动脚本

[root@xuegod63 nginx-1.14.1]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 2
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -3 $(cat $PIDF)
;;
restart)
$0 stop &> /dev/null
if [ $? -ne 0 ] ; then continue ; fi
$0 start
;;
reload)
kill -1 $(cat $PID
;;
*)
echo "Userage: $0 { start | stop | restart | reload }"
exit 1
esac
exit 0

[root@xuegod63 nginx-1.14.1]# cd

11. 配置服务开机自动启动
[root@xuegod63 ~]# chmod +x /etc/init.d/nginx
[root@xuegod63 ~]# chkconfig --add nginx
[root@xuegod63 ~]# chkconfig nginx on

 



转载于:https://www.cnblogs.com/kezi/articles/11541652.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值