NGINX宏观手记(建议收藏)
前言
任何一个工具都有它的灵魂所在,作为一个PHP程序员,我们可能仅仅使用了它的一小部分,这篇文章让你更加了解Nginx,本章大多都是总结、翻译、整理 ,希望你可以知道nginx不仅仅是PHP的附属品,更宏观的认识它的强大。
工作十二年准备的PHP进阶架构资料,如果你觉得有用,俺分享给大家:
程序猿的生活:【社群福利】30G-PHP进阶资料,助力大家都能30Kzhuanlan.zhihu.com

变量
内置变量存放在 ngx_http_core_module 模块中,变量的命名方式和apache 服务器变量是一致的。总而言之,这些变量代表着客户端请求头的内容,例如http_user_agent,httpuseragent,http_cookie, 等等。下面是nginx支持的所有内置变量。





运算符
nginx if 不允许嵌套,变量与括号之间都需要有空格,否则nginx认为是一条命令
[图片上传失败...(image-aaff59-1599554520393)]
模块
nginx 将每个功能都分成不同的模块加载,具有很强的扩展性,与php的ext一样。
下面列出的都是常用到的模块和内置的模块

命令行
nginx支持以下命令行参数

其他
配置SSL
server {
listen 443;
server_name nginx.org;
ssl on;
root /var/www/nginx.org;
index index.html index.htm;
ssl_certificate cert/nginx.pem;
ssl_certificate_key cert/nginx.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm;
}
}
配置反向代理
server {
listen 80;
server_name www.baidu.cim;
access_log logs/nginx.access.log main;
error_log logs/nginx.error.log;
root html;
index index.html index.htm index.php;
location / {
proxy_pass http://nginx.org;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
}
}
配置负载均衡
upstream server {
server 127.0.0.1:8080 weight=3;
server 127.1.1.1:8081;
}
server {
listen 80;
server_name www.baidu.cim;
access_log logs/nginx.access.log main;
error_log logs/nginx.error.log;
root html;
index index.html index.htm index.php;
location / {
proxy_pass http://server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
}
}
准备了最全大厂面试题希望能帮助到到家
程序猿的生活:PHP面试题汇总,看完这些面试题助力你面试成功,工资必有20-25Kzhuanlan.zhihu.com

以上内容希望帮助到大家,很多PHPer在进阶的时候总会遇到一些问题和瓶颈,业务代码写多了没有方向感,不知道该从那里入手去提升,对此我整理了一些资料,包括但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql优化、shell脚本、Docker、微服务、Nginx等多个知识点高级进阶干货需要的可以免费分享给大家,需要的可以点击进入暗号:知乎。
原文链接:segmentfault.com