Nginx 常用参数配置
Nginx常用参数配置
user nobody nobody; ## 指定运行用户和组
worker_processes 4; ## 指定worker数量,建议此处auto
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll; ## 使用epoll事件驱动模型
worker_connections 51200; ## 一个worker能处理的最大并发
}
http {
include mime.types;
default_type application/octet-stream;
proxy_connect_timeout 90; ## 与后端服务器连接的超时时长
proxy_send_timeout 90; ## 把请求发送给后端服务器的超时时长
proxy_read_timeout 90; ## 等待后端服务器发送响应报文的超时时长
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on; ##启用长连接马上响应,提高性能
#keepalive_timeout 0;
keepalive_timeout 65;
#开启gzip
gzip on;
gzip_http_version 1.1; ## 启用压缩时协议最小版本
gzip_vary on;
gzip_proxied any; ## 为所有代理请求启用压缩
gzip_min_length 1024; ## 设置将被gzip压缩的响应的最小长度
gzip_comp_level 6; ## 设置压缩等级
gzip_buffers 16 8k; ## 设置用于压缩响应的缓冲区number和size
gzip_proxied expired no-cache no-store private auth no_last_modified no_etag;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
upstream hservice {
server 127.0.0.1:10020;
#check interval=3000 rise=2 fall=5 timeout=100000 type=tcp;
}
upstream hweb {
server 127.0.0.1:10021;
#check interval=3000 rise=2 fall=5 timeout=100000 type=tcp;
}
server {
listen 80;
server_name localhost;
large_client_header_buffers 4 16k;
client_max_body_size 50m; ## 客户端请求体大小
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~ .*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$
{
expires 7d;
}
location ~ .*\.(?:js|css)$
{
expires 7d;
}
location ~ .*\.(?:htm|html)$
{
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
#location ~ ^/status/ {
# stub_status on; #Nginx 状态监控配置
# access_log off;
# }
location ^~ /wbWeb/ {
expires 1h;#设置静态资源缓存1小时
proxy_pass http://127.0.0.1:51000;
}
location ^~ /odWeb/ {
proxy_pass http://127.0.0.1:59001;
}
location ^~ /dingtalk/ {
proxy_pass https://oapi.dingtalk.com;
}
location ^~ /adService/ {
proxy_pass http://127.0.0.1:10020;
}
location ^~ /adWeb/ {
expires 1h;#设置静态资源缓存1小时
proxy_pass http://127.0.0.1:10021;
}
location ^~ /wbService/ {
proxy_pass http://127.0.0.1:50004;
}
location ^~ /ggWeb/ {
proxy_pass http://127.0.0.1:59002;
}
location ^~ /easy/ {
expires 1h;#设置静态资源缓存1小时
proxy_ignore_client_abort on;
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_pass http://127.0.0.1:18004;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Nginx 参考学习资料
Nginx 健康检查
https://www.cnblogs.com/oldxu/p/14143259.html
https://blog.csdn.net/chenshuai1993/article/details/83107769
https://blog.csdn.net/pcn01/article/details/105182600/
作者:努力为明天
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!