当前位置:   article > 正文

银河麒麟V10sp1服务器操作系统X86版本编译安装nginx1.8.1_ky10sp1 nginx 编译

ky10sp1 nginx 编译

编译安装nginx


前言

目前在企业内部web服务设计架构中,nginx的作为web服务器被广泛应用,编译安装能够更符合企业的实际需求以及应用


一、nginx是什么?

nginx是一款提供静态页面展示的web服务器

二、使用步骤

1.下载nginx安装

RPM包获取:Index of /packages/
源码包获取:Index of /download/

2. 创建nginx用户和组

提示:如果之前用rpm包安装,先卸载,删除nginx用户
  1. [root@uplooking tools]# groupadd -r -g 108 nginx
  2. [root@uplooking tools]# useradd -r -u 108 -g 108 nginx
  3. [root@uplooking tools]# id nginx
  4. uid=108(nginx) gid=108(nginx) 组=108(nginx)

3. 解压

[root@uplooking tools]# tar xf nginx-1.8.0.tar.gz -C /usr/local/src/

4. 准备编译配置文件

#安装依赖包:pcre-devel、zlib-devel

[root@uplooking ~]# yum install -y pcre-devel openssl-devel

#准备编译配置文件


  1. [root@uplooking ~]# cd /usr/local/src/nginx-1.8.0/
  2. ./configure \
  3. --prefix=/usr/local/nginx \
  4. --sbin-path=/usr/sbin/nginx \
  5. --conf-path=/usr/local/nginx/conf/nginx.conf \
  6. --error-log-path=/var/log/nginx/error.log \
  7. --http-log-path=/var/log/nginx/access.log \
  8. --pid-path=/var/run/nginx/nginx.pid \
  9. --lock-path=/var/lock/nginx.lock \
  10. --user=nginx \
  11. --group=nginx \
  12. --with-http_ssl_module \
  13. --with-http_flv_module \
  14. --with-http_stub_status_module \
  15. --with-http_gzip_static_module \
  16. --http-client-body-temp-path=/var/tmp/nginx/client/ \
  17. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  18. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  19. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  20. --http-scgi-temp-path=/var/tmp/nginx/scgi \
  21. --with-pcre

5.参数详解

  1. -prefix= 指向安装目录
  2. --sbin-path 指向(执行)程序文件(nginx)
  3. --conf-path= 指向配置文件(nginx.conf)
  4. --error-log-path= 指向错误日志目录
  5. --http-log-path= 指向访问日志
  6. --pid-path= 指向pid文件(nginx.pid)
  7. --lock-path= 指向lock文件(nginx.lock)(安装文件锁定,防止安装文件被别人利用,或自己误操作。)
  8. --user= 指定程序运行时的非特权用户
  9. --group= 指定程序运行时的非特权用户组
  10. --with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)
  11. --with-http_flv_module 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件)
  12. --with-http_sub_module 启用ngx_http_sub_module支持(允许用一些其他文本替换nginx响应中的一些文本)
  13. --with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
  14. --http-client-body-temp-path= 设定http客户端请求临时文件路径
  15. --http-proxy-temp-path= 设定http代理临时文件路径
  16. --http-fastcgi-temp-path= 设定http fastcgi临时文件路径
  17. --http-uwsgi-temp-path= 设定http uwsgi临时文件路径
  18. --http-scgi-temp-path= 设定http scgi临时文件路径
  19. --with-pcre 启用pcre库
  20. uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。
  21. WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx)与应用服务器(如uWSGI服务器)通信的一种规范。
  22. 要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。
  23. WSGI是一种通信协议。
  24. uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信。
  25. 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
  26. PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。
  27. SCGI协议是一个CGI(通用网关接口)协议的替代品· 它是一个应用与HTTP服务器的接口标准,类似于FastCGI,但是它设计得更为容易实现·
  28. CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序一般运行在网络服务器上。 CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。如php,perl,tcl等。

6.添加nginx.service

  1. [root@uplook system]# vim /usr/lib/systemd/system/nginx.service
  2. [Unit]
  3. Description=The nginx HTTP and reverse proxy server
  4. After=network-online.target remote-fs.target nss-lookup.target
  5. Wants=network-online.target
  6. [Service]
  7. Type=forking
  8. PIDFile=/var/run/nginx/nginx.pid
  9. # Nginx will fail to start if /run/nginx.pid already exists but has the wrong
  10. # SELinux context. This might happen when running `nginx -t` from the cmdline.
  11. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621
  12. ExecStartPre=/usr/bin/rm -f /var/run/nginx/nginx.pid
  13. #ExecStartPre=/usr/sbin/nginx -t
  14. ExecStartPre=/usr/bin/mkdir -p /var/tmp/nginx/
  15. ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  16. ExecReload=/usr/sbin/nginx -s reload
  17. KillSignal=SIGQUIT
  18. TimeoutStopSec=5
  19. KillMode=process
  20. PrivateTmp=true
  21. [Install]
  22. WantedBy=multi-user.target
  23. [root@localhost system]# systemctl daemon-reload
  24. [root@localhost system]# systemctl enable nginx
  25. Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
  26. Executing: /usr/lib/systemd/systemd-sysv-install enable nginx

  1. [root@localhost ~]# systemctl start nginx.service
  2. [root@localhost ~]# systemctl status nginx.service
  3. ● nginx.service - The nginx HTTP and reverse proxy server
  4. Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
  5. Active: active (running) since Tue 2022-07-05 14:04:02 CST; 11s ago
  6. Process: 17549 ExecStartPre=/usr/bin/rm -f /var/run/nginx/nginx.pid (code=exited, status=0/SUCCESS)
  7. Process: 17551 ExecStartPre=/usr/bin/mkdir -p /var/tmp/nginx/ (code=exited, status=0/SUCCESS)
  8. Process: 17553 ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
  9. Main PID: 17554 (nginx)
  10. Tasks: 2
  11. Memory: 1.4M
  12. CGroup: /system.slice/nginx.service
  13. ├─17554 nginx: master process /usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  14. └─17555 nginx: worker process
  15. 705 14:04:02 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
  16. 705 14:04:02 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
  17. [root@uplooking ~]# netstat -lnpt | grep 80
  18. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5268/nginx
  19. [root@uplooking ~]# lsof -i :80
  20. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  21. nginx 5268 root 6u IPv4 24467 0t0 TCP *:http (LISTEN)
  22. nginx 5270 nginx 6u IPv4 24467 0t0 TCP *:http (LISTEN)
  23. 访问测试:
  24. 浏览器访问http://主机IP

 三.加载第三方模块


NGINX 3rd Party Modules | NGINX
常用的第三方模块:
1.Development Kit
GitHub - vision5/ngx_devel_kit: Nginx Development Kit - an Nginx module that adds additional generic tools that module developers can use in their own modules
Nginx的开发工具包
 
2.Echo
HTTP Echo Module | NGINX
便捷命令,输出nginx信息
 
3.Extended status module 比较重要
wiki.nginx.org Managed WordPress Site – Just another WordPress site
Nginx status模块的扩展
 
4.Foot filter
wiki.nginx.org Managed WordPress Site – Just another WordPress site
在页面输出底部加入字符串
 
5.GeoIP 重要
wiki.nginx.org Managed WordPress Site – Just another WordPress site
IP地址识别
 
6.HTTP Push
https://pushmodule.slact.net/
将Nginx改装成comet服务
使用 HTTP 长连接、无须浏览器安装插件的两种“服务器推”



7.Limit Upload Rate 重要
GitHub - cfsego/limit_upload_rate: Limit upload rate
限制客户端上传速率
 下载模块后重新编译

8.Lua
Lua | NGINX
将lua嵌入到Nginx 极其好用的module
 Lua 是一个小巧的脚本语言

9.ModSecurity
http://www.modsecurity.org/projects/modsecurity/nginx/index.html
web应用防火墙
 增强web的安全性

10.PageSpeed
http://ngxpagespeed.com/ngx_pagespeed_example/
google开发的 高性能传输、低延时,基于nginx的页面加速
 
11.Secure Download
Secure Download | NGINX
创建安全链接
 
12.SysGuard 当web服务器并发量太大,负载太高,就会停止这个服务,保护系统
GitHub - alibaba/nginx-http-sysguard: A Nginx module to protect servers when system load or memory use goes too high.
当系统负载过高时,保护系统

1.nginx第三方模块安装方法


./configure --prefix=/你的安装目录 --add-module=/第三方模块目录
1) 在未安装nginx的情况下安装nginx第三方模块
[root@uplooking local]# unzip ngx_pagespeed-master.zip
[root@uplooking ~]# cd /usr/local/src/nginx-1.8.0/
# ./configure

--add-module=/usr/local/ngx_pagespeed-master

#make
#make install
2)在已安装nginx情况下安装nginx模块
[root@uplooking local]# unzip ngx_pagespeed-master.zip (mv ngx_pagespeed-master /usr/local )
[root@uplooking tools]# tar xf 1.9.32.10.tar.gz -C /usr/local/ngx_pagespeed-master
#提示:1.9.32.10.tar.gz为ngx_pagespeed-master支持库文件。
[root@uplooking ~]# cd /usr/local/src/nginx-1.8.0/
./configure \
--prefix=/usr/local/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_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
--add-module=/usr/local/ngx_pagespeed-master/
[root@uplooking nginx-1.8.0]# make make install之后主页会全部初始化
#编译完成后将生成的二进制文件覆盖现有的二进制文件。通常编译出来的二进制文件位于源码目录的objs/nginx
[root@uplooking nginx-1.8.0]# /etc/init.d/nginx stop
[root@uplooking nginx-1.8.0]# cp objs/nginx /usr/sbin/nginx
cp:是否覆盖"/usr/sbin/nginx"? y
[root@uplooking nginx-1.8.0]# /etc/init.d/nginx start
正在启动 nginx: [确定]

总结

安装完毕nginx添加第三方模块总结:
1、 安装nginx安装第三方模块实际上是使用--add-module重新安装一次nginx;
2、 不要make install而是直接把编译目录下objs/nginx文件直接覆盖老的nginx文件/usr/sbin/nginx;
3、 需要安装多个nginx第三方模块,只需要多指定几个相应的--add-module即可;
4、 重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里面;
5、 某些模块可能需要额外的系统安装库支持

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号