基本介绍
Nginx是一款轻量级的 Web服务器 / 反向代理服务器 / 电子邮件(IMAP/POP3)代理服务器,主要的优点是:
- 支持高并发连接,尤其是静态界面,官方测试Nginx能够支撑5万并发连接
- 内存占用极低
- 配置简单,使用灵活,可以基于自身需要增强其功能,同时支持自定义模块的开发使用灵活:可以根据需要,配置不同的负载均衡模式,URL地址重写等功能
2025年06月24日
Nginx是一款轻量级的 Web服务器 / 反向代理服务器 / 电子邮件(IMAP/POP3)代理服务器,主要的优点是:
2025年06月24日
user root;
worker_processes 16;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll; #支持大量连接和非活动连接
worker_connections 65535;
multi_accept on; #nginx在已经得到一个新连接的通知时,接收尽可能多的连接
accept_mutex on; #防止惊群现象发生,默认为on
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
client_max_body_size 20M; #设置客户端上传最大文件大小,如果继续报错继续加大
client_body_buffer_size 256K; #设置缓冲区大小提高nginx效率
fastcgi_intercept_errors on; #设置nginx处理错误信息
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
gzip_static on;
gzip on;
gzip_buffers 32 4K;
gzip_comp_level 6;
gzip_min_length 100;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png application/javascript;
gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
gzip_vary on;
server {
listen 80;
server_name localhost;
access_log logs/host.access.log main;
# if ($http_Host !~* ^127.0.0.1$) #该配置可防止host头攻击漏洞,ip根据实际情况修改
# {
# return 403;
# }
proxy_buffers 16 1024k;
proxy_buffer_size 1024k;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#server {
#listen 443 ssl;
#配置HTTPS的默认访问端口为443。
#如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
#如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
#server_name yourdomain.com; #需要将yourdomain.com替换成证书绑定的域名。
#root html;
#index index.html index.htm;
#ssl_certificate cert/cert-file-name.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。
#ssl_certificate_key cert/cert-file-name.key; #需要将cert-file-name.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; #表示使用的TLS协议的类型。
#ssl_prefer_server_ciphers on;
#location / {
# root html; #站点目录。
# index index.html index.htm;
#}
#}
}
2025年06月24日
nginx作为反向代理服务器时,报错: upstream timed out (110: Connection timed out)……
经过百度,google看到都是修改nginx配置,解决超时问题,比如:
large_client_header_buffers 4 16k;
2025年06月24日
最近,一名读者跟我说他通过浏览器访问自己的服务器时,图片显示的非常慢,以至于在浏览器中都无法完全加载出来,下载文件时,更是恼火,文件根本就无法完全下载下来。而且奇怪的是这位读者所在的网络是没啥问题的。于是,我便开始帮他排查各种问题。。。
经过一系列的排查(中间过程我就省略了,直接写重点了!),最终定位到是Nginx的问题。当我打开这位读者的网站后台管理系统,发现图片显示非常慢,在Nginx前端代理上查出如下错误信息。
2025年06月24日
Nginx为我们提供了请求限制模块(ngx_http_limit_req_module)、基于令牌桶算法的流量限制模块(
ngx_stream_limit_conn_module),可以方便的控制令牌速率,自定义调节限流,实现基本的限流控制
此模块已经合并至主线版本中,无需再额外编译添加
2025年06月24日
在server块中配置
#监听80端口
listen 80;
#监听的ip或域名
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
# 转发到127.0.0.1:8080
proxy_pass http://127.0.0.1:8080;
}
2025年06月24日
我们在网站进行文件上传的时候,出现错误提示:Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
出现 413的错误码意思是:请求实体太大!
是因为nginx中配置文件 ngnix.conf 中的
2025年06月24日
一、nginx正向代理介绍及配置(需要在客户端配置代理服务器进行指定网站访问)
#模块 ngx_http_proxy_module:
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
1、环境介绍
代理服务器系统环境为:centos
2025年06月24日
NGINX 以其卓越的性能和高并发处理能力闻名于世,但默认配置往往只是一个普适性的起点。要想真正发挥 NGINX 的潜能,满足日益增长的业务需求,深入理解其配置并进行精细化调优至关重要。这就像拥有一辆高性能跑车,还需要经验丰富的驾驶员和专业的调校才能在赛道上创造最佳成绩。