網站首頁 編程語言 正文
1. Nginx介紹:
1.1 Nginx是什么?
Nginx(“engine x”)是一個開源的,支持高性能、高并發的www服務和代理服務軟件。
由俄羅斯人Igor Sysoev開發,最初應用于俄羅斯大型網站www.rambler.ru上。
Nginx具有高并發、占用系統資源少等特性。
Nginx可以運行在UNIX、Linux、DSB、Mac OS X、Solaris及Windows等操作系統上。
1.2 Nginx主要特性
支持高并發:能支持幾萬并發連接
資源消耗少:三萬并發連接下,開始10個線程消耗內存不到200MB。
可以做HTTP反向代理及加速緩存,即負載均衡功能,內置對RS節點服務器健康檢查功能
具備Squid等專業緩存軟件的緩存功能
支持異步網絡I/O事件模型
1.3 Nginx軟件的主要功能應用
作為Web服務軟件
反向代理及負載均衡服務
前端業務數據緩存服務
2. Nginx Web服務
2.1 Nginx作為Web服務器應用場景
使用Nginx運行HTML、JS、CSS、小圖片等靜態數據
Nginx結合FastCGI運行PHP等動態程序
Nginx結合Tomcat/Resin等支持Java動態程序
2.2 如何選擇Web服務器
工作中,根據需求來選擇合適的業務服務軟件:
- 靜態業務:高并發場景,首選采用Nginx
- 動態業務:Nginx與Apache都可,建議Nginx
- 靜態+動態業務:推薦Nginx
3 編譯安裝Nginx
安裝方法多種,本文使用編譯安裝方式。如果需要大規模部署,可將業務需求定制好rpm包,然后通過Ansible安裝。
3.1 安裝pcre庫
查看當前系統版本:
cat /etc/redhat-release uname -r
結果:
CentOS release 6.10 (Final)
2.6.32-754.el6.x86_64
采用yum方式安裝pcre:
yum -y install pcre pcre-devel rpm -qa pcre pcre-devel
結果:
pcre-devel-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
3.2 安裝Nginx
檢查是否裝有openssl、openssl-devel:
rpm -qa openssl openssl-devel
結果:如果沒有,使用yum安裝
openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64
創建nginx包存放目錄:
mkdir -p /app/nginx-1.8.1 mkdir -p /server/tools cd /server/tools/
下載nginx軟件包:
官方地址:www.nginx.rog
wget -q http://nginx.org/download/nginx-1.8.1.tar.gz
創建nginx用戶:
useradd nginx -s /sbin/nologin -M
解壓軟件包并進入解壓后的目錄:
tar xf nginx-1.8.1.tar.gz cd nginx-1.8.1
進行編譯:
編譯模塊可以通過./configure --help查看
./configure --user=nginx --group=nginx --prefix=/app/nginx-1.8.1/ --with-http_stub_status_module --with-http_ssl_module
安裝:
make make install
創建軟鏈接:方便使用以及版本升級
ln -s /app/nginx-1.8.1/ /app/nginx
啟動前測試:
/app/nginx/sbin/nginx -t
結果:
nginx: the configuration file /app/nginx-1.8.1//conf/nginx.conf syntax is oknginx: configuration file /app/nginx-1.8.1//conf/nginx.conf test is successful
啟動Nginx服務并檢查端口:
/app/nginx/sbin/nginx netstat -utpln | grep 80
結果:
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:80 ? ? ? ? ? ? ? ? ?0.0.0.0:* ? ? ? ? ? ? ? ? ? LISTEN ? ? ?13689/nginx
檢查Nginx啟動結果:以下內容代表啟動成功
curl 192.168.1.31
結果:
Welcome to nginx! Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
4. Nginx目錄結構與配置文件
4.1 Nginx目錄結構說明
tree /app/nginx
/app/nginx ├── client_body_temp ├── conf #nginx配置文件目錄 │ ├── fastcgi.conf #fastcgi相關參數配置文件 │ ├── fastcgi.conf.default │ ├── fastcgi_params #fastcgi參數文件 │ ├── fastcgi_params.default │ ├── koi-utf │ ├── koi-win │ ├── mime.types #媒體類型 │ ├── mime.types.default │ ├── nginx.conf #Nginx主配置文件 │ ├── nginx.conf.default │ ├── scgi_params #scgi配置文件 │ ├── scgi_params.default │ ├── uwsgi_params #uwsgi配置文件 │ ├── uwsgi_params.default │ └── win-utf ├── fastcgi_temp #fastcgi臨時數據文件 ├── html #默認站點目錄 │ ├── 50x.html #錯誤頁面顯示文件 │ └── index.html #默認的站點首頁文件 ├── logs #默認日志路徑 │ ├── access.log #默認訪問日志文件 │ ├── error.log #默認錯誤日志文件 │ └── nginx.pid #Nginx的pid文件 ├── proxy_temp #臨時目錄 ├── sbin #Nginx命令目錄 │ ├── nginx #啟動命令 │ └── nginx.old ├── scgi_temp #臨時目錄 └── uwsgi_temp #臨時目錄 9 directories, 22 files
4.2 Nginx主配置文件
去注釋顯示配置文件:
egrep -v "#|^$" /app/nginx/conf/nginx.conf.default
結果:
worker_processes 1; #worker進程數量 events { #事件區塊開始 worker_connections 1024; #單worker進程支持的最大連接 } #事件區塊結束 http { #HTTP區塊開始 include mime.types; #支持的媒體類型庫 default_type application/octet-stream; #默認媒體類型 sendfile on; #開啟高效傳輸模式 keepalive_timeout 65; #連接超時 server { #server區塊開始 listen 80; #服務端口,默認80 server_name localhost; #域名主機名 location / { #location區塊開始 root html; #站點根目錄 index index.html index.htm; #默認首頁文件 } #location區塊結束 error_page 500 502 503 504 /50x.html;#對應狀態碼及回應 location = /50x.html { #location開始回應50x.html root html; #站點目錄為html } } } #HTTP區塊結束
注:server區塊和location區塊可以是多個。
原文鏈接:https://yyang.blog.csdn.net/article/details/107584865
相關推薦
- 2022-03-16 .Net?6中WebApplicationBuilder介紹和用法_自學過程
- 2023-10-16 element--el-input限制輸入為數字且必須大于0
- 2023-01-08 C#實現屏幕抓圖并保存的示例代碼_C#教程
- 2022-07-24 示例剖析golang中的CSP并發模型_Golang
- 2022-09-13 iOS開發之UIMenuController使用示例詳解_IOS
- 2022-03-15 在Linux+Jexus中發布和部署Asp.Net?Core_自學過程
- 2021-12-01 C語言多維數組數據結構的實現詳解_C 語言
- 2022-09-15 python安裝whl文件的實戰步驟_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支