Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Nginx基础知识
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Allen Liu
June 24, 2012
Technology
370
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Nginx基础知识
Nginx基础知识
Allen Liu
June 24, 2012
More Decks by Allen Liu
See All by Allen Liu
字符集科普知识
liuxd
1
76
vagrant介绍
liuxd
2
320
PHP5.3、PHP5.4的特性介绍与深度挖掘
liuxd
3
340
Node.js那些事儿
liuxd
2
1.6k
Other Decks in Technology
See All in Technology
TypeScript入門 2026
recruitengineers
PRO
3
580
【AG-UI × A2UI × MCP Apps】Generative UIをやさしく解説する
nrinetcom
PRO
1
120
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
2
240
認知負荷をGemini で溶かす — GKE 基盤「Orbit」における AI エージェントの実践
sansantech
PRO
1
300
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
250
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
カートの信頼性を担保するWireMockを使ったe2eテスト
ykagano
0
280
AIコーディングの次。コードレビューと理解負荷を解消して組織の開発生産性を高める
moongift
PRO
2
2.6k
【CEDEC2026】『ウマ娘 プリティーダービー』 英語版のキャラクターの方言や口調をローカライズするための創造的アプローチ
cygames
PRO
2
870
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
170
SO-101×VLAによる3色キューブのピック&プレース
abeja
0
200
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
7.3k
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
250
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
430
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
490
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
210
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
270
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Deep Space Network (abreviated)
tonyrice
0
250
Transcript
Nginx Nginx Nginx Nginx基础知识 基础知识 基础知识 基础知识 东子 东子 东子
东子 著 著 著 著
2 内容结构 内容结构 内容结构 内容结构 • 特性介绍 • 安装指南 •
管理命令 • 配置文件
3 内容结构 内容结构 内容结构 内容结构 • 特性介绍 • 安装指南 •
管理命令 • 配置文件
4 没错,这是匹黑马! 没错,这是匹黑马! 没错,这是匹黑马! 没错,这是匹黑马!
5 各种优点 各种优点 各种优点 各种优点 1.异步非阻塞 2.缓存文件描述符 3.简单的负载均衡 4.热部署
6 适合场景 适合场景 适合场景 适合场景 • LB • 静态文件服务器 •
Web应用服务器
7 内容结构 内容结构 内容结构 内容结构 • 特性介绍 • 安装指南 •
管理命令 • 配置文件
8 安装指南 安装指南 安装指南 安装指南 • 安装命令:apt-get install nginx •
重要路径: 1,运行文件路径:/usr/sbin/nginx 2,配置文件路径:/etc/nginx/
9 内容结构 内容结构 内容结构 内容结构 • 特性介绍 • 安装指南 •
管理命令 • 配置文件
10 管理命令:启动、关闭 管理命令:启动、关闭 管理命令:启动、关闭 管理命令:启动、关闭 • 启动:nginx -c /usr/nginx/nginx.conf •
关闭: 1,kill -QUIT `cat /var/run/nginx.pid` 2,kill -TERM `cat /var/run/nginx.pid`
11 管理命令:重启、检查配置 管理命令:重启、检查配置 管理命令:重启、检查配置 管理命令:重启、检查配置 • 重启: 1,kill -HUP `cat
/var/run/nginx.pid` 2,nginx -s reload • 检测配置: nginx -t /usr/nginx/nginx.conf
12 内容结构 内容结构 内容结构 内容结构 • 特性介绍 • 安装指南 •
管理命令 • 配置文件
13 配置文件 配置文件 配置文件 配置文件 • 语法规则 • 负载均衡 •
整合php-fpm • 如何rewrite
14 配置文件 配置文件 配置文件 配置文件- - - -语法规则 语法规则 语法规则
语法规则- - - -结构 结构 结构 结构
15 配置文件 配置文件 配置文件 配置文件- - - -语法规则 语法规则 语法规则
语法规则- - - -全局配置 全局配置 全局配置 全局配置 • user www www • worker_proccesses 4 • worker_rlimit_nofile 10240 • pid /var/run/nginx.pid • error_log /var/error.log info [ debug | info | notice | warn | error | crit]
16 配置文件 配置文件 配置文件 配置文件- - - -语法规则 语法规则 语法规则
语法规则-server -server -server -server • listen 80 • server_name localhost • access_log /var/log/access.log main [main,timing,up_head,mine] • log_format main '$remote_addr - $remote_user [$time_local] '
17 配置文件 配置文件 配置文件 配置文件- - - -负载均衡 负载均衡 负载均衡
负载均衡- - - -样例 样例 样例 样例 http { upstream myproject { server 127.0.0.1:8000 weight=3; server 127.0.0.1:8001 } server { listen 80; server_name www.domain.com; location / { proxy_pass http://myproject; } } }
18 配置文件 配置文件 配置文件 配置文件- - - -负载均衡 负载均衡 负载均衡
负载均衡- - - -策略 策略 策略 策略 策略: 策略: 策略: 策略:轮询,weight,ip_hash ip_hash 写法: upstream myproject { server 127.0.0.1:8000; server 127.0.0.1:8001; ip_hash; } 补充: 补充: 补充: 补充:down,backup
19 配置文件 配置文件 配置文件 配置文件- - - -整合 整合 整合
整合PHP-nginx PHP-nginx PHP-nginx PHP-nginx相关配置 相关配置 相关配置 相关配置 server { listen 80; server_name www.domain.com; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } }
20 配置文件 配置文件 配置文件 配置文件- - - -整合 整合 整合
整合PHP-php-fpm PHP-php-fpm PHP-php-fpm PHP-php-fpm • 必要编译参数: 必要编译参数: 必要编译参数: 必要编译参数:--enable-fpm • 必要配置选项: 必要配置选项: 必要配置选项: 必要配置选项:listen 127.0.0.1:9000 • 管理命令: 管理命令: 管理命令: 管理命令: 1,php-fpm 2,kill -INT `cat /var/php-fpm.pid` 3,kill -USR2 `cat /var/php-fpm.pid`
21 配置文件 配置文件 配置文件 配置文件-rewrite- -rewrite- -rewrite- -rewrite-指令列表 指令列表 指令列表
指令列表 • set set set set • break break break break • return return return return • if if if if • rewrite rewrite rewrite rewrite
22 配置文件 配置文件 配置文件 配置文件-rewrite- -rewrite- -rewrite- -rewrite-指令: 指令: 指令:
指令:if if if if • 相等与不等: 相等与不等: 相等与不等: 相等与不等:= = = =, , , ,!= != != != • 检测符号: 检测符号: 检测符号: 检测符号:-f,-d,-e,-x -f,-d,-e,-x -f,-d,-e,-x -f,-d,-e,-x • 匹配正则: 匹配正则: 匹配正则: 匹配正则: ~,大小写敏感匹配 ~,大小写敏感匹配 ~,大小写敏感匹配 ~,大小写敏感匹配 ~ ~ ~ ~* * * *,大小写不敏感匹配 ,大小写不敏感匹配 ,大小写不敏感匹配 ,大小写不敏感匹配 ! ! ! !~,大小写敏感不匹配 ~,大小写敏感不匹配 ~,大小写敏感不匹配 ~,大小写敏感不匹配 ! ! ! !~ ~ ~ ~* * * *,大小写不敏感不匹配 ,大小写不敏感不匹配 ,大小写不敏感不匹配 ,大小写不敏感不匹配
23 配置文件 配置文件 配置文件 配置文件-rewrite- -rewrite- -rewrite- -rewrite-指令: 指令: 指令:
指令:if if if if例子 例子 例子 例子 例子 例子 例子 例子1 1 1 1: : : : if ($request_method = POST ) { if ($request_method = POST ) { if ($request_method = POST ) { if ($request_method = POST ) { return 405; return 405; return 405; return 405; } } } } 例子 例子 例子 例子2 2 2 2: : : : if (!-f $request_filename) { if (!-f $request_filename) { if (!-f $request_filename) { if (!-f $request_filename) { break; break; break; break; proxy_pass http://127.0.0.1; proxy_pass http://127.0.0.1; proxy_pass http://127.0.0.1; proxy_pass http://127.0.0.1; } } } } 例子 例子 例子 例子3 3 3 3: : : : if ($http_user_agent ~ MSIE) { if ($http_user_agent ~ MSIE) { if ($http_user_agent ~ MSIE) { if ($http_user_agent ~ MSIE) { rewrite ^(. rewrite ^(. rewrite ^(. rewrite ^(.* * * *)$ /msie/$1 )$ /msie/$1 )$ /msie/$1 )$ /msie/$1 break; break; break; break; } } } }
24 配置文件 配置文件 配置文件 配置文件-rewrite- -rewrite- -rewrite- -rewrite-指令: 指令: 指令:
指令:rewrite rewrite rewrite rewrite • 用法: 用法: 用法: 用法:rewrite rewrite rewrite rewrite 正则 正则 正则 正则 替换 替换 替换 替换 标志位 标志位 标志位 标志位 • rewrite rewrite rewrite rewrite的生效区块为 的生效区块为 的生效区块为 的生效区块为server, location, if server, location, if server, location, if server, location, if • rewrite rewrite rewrite rewrite只对相对路径进行匹配 只对相对路径进行匹配 只对相对路径进行匹配 只对相对路径进行匹配, , , ,不处理 不处理 不处理 不处理host host host host。 。 。 。 • 标志位: 标志位: 标志位: 标志位: 1. break:停止rewrite检测,rewrite的最终结果。 • last:停止当前区块rewrite检测,转而去其他location尝 试匹配。 • redirect:返回302,临时重定向。 1. permanent:返回301,永久重定向。
25 配置文件 配置文件 配置文件 配置文件-rewrite- -rewrite- -rewrite- -rewrite-指令: 指令: 指令:
指令:rewrite rewrite rewrite rewrite例子 例子 例子 例子 break例子: rewrite ^/media/(.*)\..*$ $1/mp3 break; last例子: rewrite ^/media/(.*)\..*$ $1/mp3 last; redirect例子: rewrite ^(.*)$ http://newdomain.com/ redirect; permanent例子: rewrite ^(.*)$ http://newdomain.com/ permanent;
3x 3x 3x 3x