阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下Nginx源码编译安装

447次阅读
没有评论

共计 11234 个字符,预计需要花费 29 分钟才能阅读完成。

什么是 Nginx?

Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下 Nginx 是 Apache 服务器不错的替代品. 其特点是占有内存少,并发能力强,事实上 nginx 的并发能力确实在同类型的网页服务器中表现较好. 目前中国大陆使用 nginx 网站用户有:新浪、网易、腾讯,另外知名的微网志 Plurk 也使用 nginx。

Nginx 作为 负载均衡 服务器:

Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。Nginx 采用 C 进行编写,不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器:

Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持 perl 语法),Bugs 非常少的服务器:Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。你还能够不间断服务的情况下进行软件版本的升级。

官网下载

点击下载

[root@nginx ~]# ls
 nginx-1.15.2.tar.gz

安装依赖软件

## 安装编译工具 gcc
[root@nginx ~]# yum install -y gcc

## 安装 PCRE 库,pcre 提供编译版本的库,pcre-devel 提供开发阶段的头文件和编译项目的源代码。
[root@nginx ~]# yum install -y pcre pcre-devel 

## 安装 OpenSSL 加密库,nginx 中如果服务器需要提供安全网页则会用到 OpenSSL 库
[root@nginx ~]# yum install -y openssl  openssl-devel

## 安装 zlib 库,zlib 库提供了压缩算法,在 nginx 的各种模块中需要使用 gzip 压缩
[root@nginx ~]# yum install -y zlib  zlib-devel

解压

[root@nginx ~]# tar  zxf  nginx-1.15.2.tar.gz
[root@nginx ~]# ls
nginx-1.15.2  nginx-1.15.2.tar.gz

查看模块

[root@nginx ~]# cd nginx-1.15.2
[root@nginx nginx-1.15.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

[root@nginx nginx-1.15.2]# ./configure –help    ## 查看参数

  –help                            print this message

  –prefix=PATH                      nginx 安装路径
  –sbin-path=PATH                  nginx 二进制执行文件路径
  –modules-path=PATH                set modules path
  –conf-path=PATH                  nginx 配置文件存放位置
  –error-log-path=PATH              错误日志文件路径
  –pid-path=PATH                    nginx.pid 文件路径(pid 文件包含进程的标识符)
  –lock-path=PATH                  锁文件存放路径(锁文件(nginx.log) 用于控制 nginx 进程没有被启动两次))

  –user=USER                        指定启动 nginx 进程的默认用户;set non-privileged user for worker processes
  –group=GROUP                      指定启动 nginx 进程的默认用户组;set non-privileged group for worker processes

  –build=NAME                      set build name
  –builddir=DIR                    set build directory

  –with-select_module              enable select module
  –without-select_module            disable select module
  –with-poll_module                enable poll module
  –without-poll_module              disable poll module

  –with-threads                    enable thread pool support

  –with-file-aio                    enable file AIO support

  –with-http_ssl_module            enable ngx_http_ssl_module
  –with-http_v2_module              enable ngx_http_v2_module
  –with-http_realip_module          enable ngx_http_realip_module
  –with-http_addition_module        enable ngx_http_addition_module
  –with-http_xslt_module            enable ngx_http_xslt_module
  –with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  –with-http_image_filter_module    enable ngx_http_image_filter_module
  –with-http_image_filter_module=dynamic
                                    enable dynamic ngx_http_image_filter_module
  –with-http_geoip_module          enable ngx_http_geoip_module
  –with-http_geoip_module=dynamic  enable dynamic ngx_http_geoip_module
  –with-http_sub_module            enable ngx_http_sub_module
  –with-http_dav_module            enable ngx_http_dav_module
  –with-http_flv_module            enable ngx_http_flv_module
  –with-http_mp4_module            enable ngx_http_mp4_module
  –with-http_gunzip_module          enable ngx_http_gunzip_module
  –with-http_gzip_static_module    enable ngx_http_gzip_static_module
  –with-http_auth_request_module    enable ngx_http_auth_request_module
  –with-http_random_index_module    enable ngx_http_random_index_module
  –with-http_secure_link_module    enable ngx_http_secure_link_module
  –with-http_degradation_module    enable ngx_http_degradation_module
  –with-http_slice_module          enable ngx_http_slice_module
  –with-http_stub_status_module    enable ngx_http_stub_status_module

  –without-http_charset_module      disable ngx_http_charset_module
  –without-http_gzip_module        disable ngx_http_gzip_module
  –without-http_ssi_module          disable ngx_http_ssi_module
  –without-http_userid_module      disable ngx_http_userid_module
  –without-http_access_module      disable ngx_http_access_module
  –without-http_auth_basic_module  disable ngx_http_auth_basic_module
  –without-http_mirror_module      disable ngx_http_mirror_module
  –without-http_autoindex_module    disable ngx_http_autoindex_module
  –without-http_geo_module          disable ngx_http_geo_module
  –without-http_map_module          disable ngx_http_map_module
  –without-http_split_clients_module disable ngx_http_split_clients_module
  –without-http_referer_module      disable ngx_http_referer_module
  –without-http_rewrite_module      disable ngx_http_rewrite_module
  –without-http_proxy_module        disable ngx_http_proxy_module
  –without-http_fastcgi_module      disable ngx_http_fastcgi_module
  –without-http_uwsgi_module        disable ngx_http_uwsgi_module
  –without-http_scgi_module        disable ngx_http_scgi_module
  –without-http_grpc_module        disable ngx_http_grpc_module
  –without-http_memcached_module    disable ngx_http_memcached_module
  –without-http_limit_conn_module  disable ngx_http_limit_conn_module
  –without-http_limit_req_module    disable ngx_http_limit_req_module
  –without-http_empty_gif_module    disable ngx_http_empty_gif_module
  –without-http_browser_module      disable ngx_http_browser_module
  –without-http_upstream_hash_module
                                    disable ngx_http_upstream_hash_module
  –without-http_upstream_ip_hash_module
                                    disable ngx_http_upstream_ip_hash_module
  –without-http_upstream_least_conn_module
                                    disable ngx_http_upstream_least_conn_module
  –without-http_upstream_random_module
                                    disable ngx_http_upstream_random_module
  –without-http_upstream_keepalive_module
                                    disable ngx_http_upstream_keepalive_module
  –without-http_upstream_zone_module
                                    disable ngx_http_upstream_zone_module

  –with-http_perl_module            enable ngx_http_perl_module
  –with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
  –with-perl_modules_path=PATH      set Perl modules path
  –with-perl=PATH                  set perl binary pathname

  –http-log-path=PATH              set http access log pathname
  –http-client-body-temp-path=PATH  set path to store
                                    http client request body temporary files
  –http-proxy-temp-path=PATH        set path to store
                                    http proxy temporary files
  –http-fastcgi-temp-path=PATH      set path to store
                                    http fastcgi temporary files
  –http-uwsgi-temp-path=PATH        set path to store
                                    http uwsgi temporary files
  –http-scgi-temp-path=PATH        set path to store
                                    http scgi temporary files

  –without-http                    disable HTTP server
  –without-http-cache              disable HTTP cache

  –with-mail                        enable POP3/IMAP4/SMTP proxy module
  –with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
  –with-mail_ssl_module            enable ngx_mail_ssl_module
  –without-mail_pop3_module        disable ngx_mail_pop3_module
  –without-mail_imap_module        disable ngx_mail_imap_module
  –without-mail_smtp_module        disable ngx_mail_smtp_module

  –with-stream                      enable TCP/UDP proxy module
  –with-stream=dynamic              enable dynamic TCP/UDP proxy module
  –with-stream_ssl_module          enable ngx_stream_ssl_module
  –with-stream_realip_module        enable ngx_stream_realip_module
  –with-stream_geoip_module        enable ngx_stream_geoip_module
  –with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  –with-stream_ssl_preread_module  enable ngx_stream_ssl_preread_module
  –without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  –without-stream_access_module    disable ngx_stream_access_module
  –without-stream_geo_module        disable ngx_stream_geo_module
  –without-stream_map_module        disable ngx_stream_map_module
  –without-stream_split_clients_module
                                    disable ngx_stream_split_clients_module
  –without-stream_return_module    disable ngx_stream_return_module
  –without-stream_upstream_hash_module
                                    disable ngx_stream_upstream_hash_module
  –without-stream_upstream_least_conn_module
                                    disable ngx_stream_upstream_least_conn_module
  –without-stream_upstream_random_module
                                    disable ngx_stream_upstream_random_module
  –without-stream_upstream_zone_module
                                    disable ngx_stream_upstream_zone_module

  –with-google_perftools_module    enable ngx_google_perftools_module
  –with-cpp_test_module            enable ngx_cpp_test_module

  –add-module=PATH                  enable external module
  –add-dynamic-module=PATH          enable dynamic external module

  –with-compat                      dynamic modules compatibility

  –with-cc=PATH                    set C compiler pathname
  –with-cpp=PATH                    set C preprocessor pathname
  –with-cc-opt=OPTIONS              set additional C compiler options
  –with-ld-opt=OPTIONS              set additional linker options
  –with-cpu-opt=CPU                build for the specified CPU, valid values:
                                    pentium, pentiumpro, pentium3, pentium4,
                                    athlon, opteron, sparc32, sparc64, ppc64

  –without-pcre                    disable PCRE library usage
  –with-pcre                        force PCRE library usage
  –with-pcre=DIR                    set path to PCRE library sources
  –with-pcre-opt=OPTIONS            set additional build options for PCRE
  –with-pcre-jit                    build PCRE with JIT compilation support

  –with-zlib=DIR                    set path to zlib library sources
  –with-zlib-opt=OPTIONS            set additional build options for zlib
  –with-zlib-asm=CPU                use zlib assembler sources optimized
                                    for the specified CPU, valid values:
                                    pentium, pentiumpro

  –with-libatomic                  force libatomic_ops library usage
  –with-libatomic=DIR              set path to libatomic_ops library sources

  –with-openssl=DIR                set path to OpenSSL library sources
  –with-openssl-opt=OPTIONS        set additional build options for OpenSSL

  –with-debug                      enable debug logging

添加模块,编译

[root@nginx nginx-1.15.2]# ./configure –prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module –with-file-aio –with-threads –user=nginx –group=nginx

编译成功后执行安装命令

[root@nginx nginx-1.15.2]# make && make install

添加用户

[root@server1 nginx-1.10.1]# useradd -s /sbin/nologin -M nginx

创建软链接,便于启动

[root@nginx nginx-1.15.2]# ln  -s  /usr/local/lnmp/nginx/sbin/nginx  /usr/local/sbin/

开启 Nginx

[root@nginx nginx-1.15.2]# nginx
[root@nginx nginx-1.15.2]# ps ax| grep nginx
 7066 ?        Ss    0:00 nginx: master process nginx
 7067 ?        S      0:00 nginx: worker process
 7069 pts/0    S+    0:00 grep –color=auto nginx

至此,已经成功安装 Nginx,访问 http:ip

平滑加载

[root@nginx nginx-1.15.2]# nginx  -s  reload

关闭 Nginx

[root@nginx nginx-1.15.2]# nginx  -s  stop

编译时选择需要的模块不同,或者需要改变安装路径、用户等,则要重新编译或者重新安装 Nginx

重新编译

[root@nginx ~]# ls
nginx-1.15.2  nginx-1.15.2.tar.gz
[root@nginx ~]# cd nginx-1.15.2
[root@nginx nginx-1.15.2]# make clean
rm -rf Makefile objs
[root@nginx nginx-1.15.2]# ./configure –prefix=/usr/local/web/nginx –with-http_ssl_module –with-http_stub_status_module –with-file-aio –with-threads –user=nginx –group=nginx

## 注意重新编译仅仅 make 不用 make install
[root@nginx nginx-1.15.2]# make
[root@nginx nginx-1.15.2]# nginx
[root@nginx nginx-1.15.2]# ps xa| grep nginx
 9728 ?        Ss    0:00 nginx: master process nginx
 9729 ?        S      0:00 nginx: worker process
 9732 pts/0    S+    0:00 grep –color=auto nginx
 [root@nginx nginx-1.15.2]# nginx -s stop

重新安装

[root@nginx ~]# ls
nginx-1.15.2  nginx-1.15.2.tar.gz
[root@nginx ~]# cd nginx-1.15.2
[root@nginx nginx-1.15.2]# make clean
rm -rf Makefile objs
[root@nginx nginx-1.15.2]# ./configure –prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module –with-file-aio –with-threads –user=nginx –group=nginx

## 注意重新安装 nginx 时,需要 make && make install
[root@nginx nginx-1.15.2]# make && make install
[root@nginx nginx-1.15.2]# nginx
[root@nginx nginx-1.15.2]# ps xa| grep nginx
12419 ?        Ss    0:00 nginx: master process nginx
12420 ?        S      0:00 nginx: worker process
12422 pts/0    S+    0:00 grep –color=auto nginx
[root@nginx nginx-1.15.2]# nginx -s stop

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计11234字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7983390
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

还在忍受动辄数百兆的“全家桶”监控软件?后台偷占资源、界面杂乱冗余,想查个 CPU 温度都要层层点选? 今天给...
星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛 NAS 硬件 02:某鱼 6 张左右就可拿下 5 盘位的飞牛圣体 NAS 前言 大家好,我是星...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
我用AI做了一个1978年至2019年中国大陆企业注册的查询网站

我用AI做了一个1978年至2019年中国大陆企业注册的查询网站

我用 AI 做了一个 1978 年至 2019 年中国大陆企业注册的查询网站 最近星哥在 GitHub 上偶然...
浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍

浏览器自动化工具!开源 AI 浏览器助手让你效率翻倍 前言 在 AI 自动化快速发展的当下,浏览器早已不再只是...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
免费无广告!这款跨平台AI RSS阅读器,拯救你的信息焦虑

免费无广告!这款跨平台AI RSS阅读器,拯救你的信息焦虑

  免费无广告!这款跨平台 AI RSS 阅读器,拯救你的信息焦虑 在算法推荐主导信息流的时代,我们...
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸 前言 作为天天跟架构图、拓扑图死磕的...
三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Android 的最优解?

  三大开源投屏神器横评:QtScrcpy、scrcpy、escrcpy 谁才是跨平台控制 Andr...
星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛NAS-11:咪咕视频订阅部署全攻略

星哥带你玩飞牛 NAS-11:咪咕视频订阅部署全攻略 前言 在家庭影音系统里,NAS 不仅是存储中心,更是内容...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...