linux编译安装nginx
生活随笔
收集整理的這篇文章主要介紹了
linux编译安装nginx
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
- 系統:centos7和debian11均驗證可行
- 本文將nginx默認支持的編譯參數都加上了,所以需要的依賴比較多,酌情配置。
步驟
- 假設安裝在
/usr/local/nginx,創建安裝目錄
mkdir -p /usr/local/nginx
- 下載源碼包:http://nginx.org/en/download.html
- 安裝依賴包:
# yum
yum -y install gcc pcre-devel zlib-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel jemalloc-devel libatomic_ops-devel perl-devel perl-ExtUtils-Embeb
# apt
apt install -y libpcre3-dev openssl libssl-dev libxml2-dev libgd-dev libxml2 libgeoip-dev libxslt-dev
- 預編譯:
./configure \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \s
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit \
--prefix=/usr/local/nginx
- 編譯:
make - 編譯安裝:
make install
配置文件簡單優化
- 啟動進程數,通常設置成和CPU的數量相等或者auto
worker_processes auto;
worker_cpu_affinity auto;
- nginx打開的最多文件描述符數量(一個nginx打開的最多文件描述符數目,理論值應為最多打開文件數與nginx進程數相除,但nginx分配請求并不均勻,可以與 ulimit -n 的值保持一致)
worker_rlimit_nofile 102400;
- event塊
events {
use epoll;(epoll是多路復用IO的一種方式,但是僅用于linux 2.6以上版本的內核,可以大幅提高nginx的性能)
worker_connections 102400;(單個工作進程的最大并發連接數。最大連接數 = 連接數 * 進程數)
accept_mutex on;(對多個nginx進程進行序列化,避免多個進程對連接的爭搶。)
multi_accept on;(盡可能地接受請求)
}
基礎命令
nginx -t:檢查nginx配置文件是否語法正確nginx -c /usr/local/nginx/conf/nginx.conf:指定nginx配置文件nginx -s reload:熱加載nginx配置nginx -s quit:安全停止nginx
總結
以上是生活随笔為你收集整理的linux编译安装nginx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 漫谈NIO(3)之Netty实现
- 下一篇: 手记系列之七 ----- 分享Linux