Centos7安裝nginx(源碼安裝 不是yum)和安裝Stream模塊的編譯

nginx從 1.9.0開始,新增長了一個stream模塊,用來實現四層協議的轉發、代理或者負載均衡等。這徹底就是搶HAproxy份額的節奏,鑑於nginx在7層負載均衡和web service上的成功,和nginx良好的框架,stream模塊前景一片光明。
ngx_stream_core_module模塊
是模擬反代基於tcp或udp的服務鏈接,即工做於傳輸層的反代或調度器

Nginx版本:1.18.0html

1.下載NGINX穩定發行版node

wget https://nginx.org/download/nginx-1.18.0.tar.gz

2.解壓並切換到安裝目錄linux

tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

3.編譯安裝nginx

默認路徑安裝c++

yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

./configure --with-stream或者

./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-pcre --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_stub_status_module --with-streamweb



make
&& make install


配置文件路徑爲/usr/local/nginx/conf/ 
和啓動路徑/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx  -s start

 

 

指定nginx.config路徑安裝正則表達式

yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

./configure --prefix=/opt/nginx --sbin-path=/opt/nginx/sbin/nginx --conf-path=/opt/nginx/conf/nginx.conf --with-http_stub_status_module --with-http_gzip_static_module --with-stream
make
make install
cd /opt/nginx
配置文件路徑/opt/nginx/conf/nginx.conf
和啓動路徑/opt/nginx/sbin/nginx -s reload

yum卸載nginx參考連接 https://blog.csdn.net/a704397849/article/details/100569176瀏覽器

源碼安裝卸載 sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx緩存

nginx:未找到命令(command not found)解決方法 加入環境變量:https://www.jianshu.com/p/3aef06a614bcbash

service nginx start啓動nginx出現Failed to start nginx.service:unit not found   :https://blog.csdn.net/qq_38269316/article/details/82860941

 

nginx基本操做命令

    systemctl start nginx.service(service nginx start)

    systemctl stop nginx.service(service nginx stop)

    systemctl reload nginx.service(service nginx restart)

    systemctl status nginx.service(service nginx status)

補充資料

--prefix=path:設置Nginx的安裝路徑,不寫的話默認是在/usr/local/nginx
--sbin-path=path:設置Nginx的可執行文件路徑,默認路徑是prefix/sbin/nginx
--conf-path=path:設置Nginx配置文件路徑,默認路徑是prefix/conf/nginx.conf
--pid-path=path:設置Nginx pid文件路徑,默認路徑是prefix/logs/nginx.pid
--error-log-path=path:設置錯誤日誌存放路徑,默認路徑是prefix/logs/error.log
--http-log-path=path:設置訪問日誌存放路徑,默認路徑是prefix/logs/access.log
--user=name:設置運行Nginx的用戶,默認用戶是nobody
--group=name:設置運行Nginx的用戶組,默認用戶組是nobody
--with-http_ssl_module:啓用Nginx的SSL功能
--with-http_realip_module:該模塊能夠記錄原始客戶端的IP而不是負載均衡的IP
--with-http_sub_module:文字內容替換模塊,可用於替換全站敏感字等
--with-http_flv_module:開啓對FLV格式文件的支持
--with-http_mp4_module:開啓對MP4格式文件的支持
--with-http_gzip_module:提供對gzip壓縮的支持
--with-http_stub_status_module:開啓Nginx狀態監控模塊
--with-pcre:支持正則表達式

Nginx主配置文件參數詳解

user nginx; #定義運行Nginx的用戶
worker_processes 2;#Nginx所開啓的進程數,一般和cpu個數相等或者設置爲auto
worker_cpu_affinity auto; #自動進行CPU親和設置
worker_cpu_affinity 0000000000000001 000000000000010 #手動進行CPU親和設置
worker_rlimit_nofile 65535; #一個worker進程最多能打開的文件數
error_log logs/error.log warn; #Nginx服務的錯誤日誌路徑與記錄級別
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535; #設置Nginx進程文件句柄數
events { worker_connections 10240; #每一個進程的併發數 use epoll; }
http {
include mime.types; #文件擴展名與文件類型映射表
default_type application/octet-stream; #默認文件類型
charset utf-8; #默認字符集
log_format main #定義日誌格式
access_log logs/access.log main; #訪問日誌存放路徑與日誌記錄格式,這裏main就是上一步log_format所定義的main
sendfile on;
tcp_nopush on; #一次傳輸多個數據包,提升傳輸效率
#tcp_nodeley off #與tcp_nopush相反,實時性要求比較高的場景會打開這個
keepalive_timeout 65; #長鏈接超時時間爲65秒
gzip on; #打開gzip後經過瀏覽器開發者工具-網絡功能能夠看到size大小被壓縮了,對文本類型的文件壓縮效率最高,可做用於location中
include /etc/nginx/conf.d/*.conf #conf.d目錄下的配置文件也會生效
server { listen 80; server_name linuxe.cn www.linuxe.cn; #精確匹配優先級最高,支持正則匹配,若是都不匹配則匹配default server access_log logs/access.log main; #單獨對主機記錄日誌 location ~ .*\.(jpg|gif|png)$ { gzip on; expires 24h; #開啓緩存,若是是取的緩存數據,瀏覽器開發者工具中返回狀態是304 root html; index index.html index.htm; } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
其中main和events都是全局性標籤;
而server標籤負責了每一個虛擬主機的配置,
在server標籤中還存在localtion標籤,能夠根據條件匹配來對不一樣的訪問路徑作不一樣的配置,實現URL轉發等功能。
localtion標籤有着一個匹配順序須要注意,這是常常出錯的地方,下面是localtion優先級排序示例;
location = /uri #精確匹配,優先級最高
location ^~ /uri #普通字符串匹配,不支持正則表達式,當匹配成功後中止其餘location匹配,優先級高於正則
location ~ #區分大小寫的正則匹配
location ~* #不區分大小寫的正則匹配
location /uri #前綴匹配
location / #通用匹配

 

sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx從新安裝http://blog.chinaunix.net/uid-69994259-id-5845151.html已經yum安裝的 須要添加第三方模塊或者平滑升級時候 參考下面連接https://www.136.la/nginx/show-77740.htmlhttps://blog.csdn.net/qq_37638061/article/details/90581358
相關文章
相關標籤/搜索