nginx 高性能的 nginxconf 配置
以下是一个基本的 nginx.conf 配置文件,可以实现高性能的代理和负载平衡:
# 全局配置
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
use epoll;
}
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 /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
# 反向代理配置
upstream backend {
server backend1.example.com:8080 weight=10 max_fails=3 fail_timeout=30s;
server backend2.example.com:8080 weight=10 max_fails=3 fail_timeout=30s;
server backend3.example.com:8080 weight=10 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
该配置文件中,worker_processes 表示启动的工作进程数,worker_connections 表示每个工作进程的最大连接数。upstream 定义了反向代理的后端服务器列表,可以根据实际情况进行配置。proxy_pass 表示将请求转发到后端服务器,proxy_set_header 表示设置请求头信息。除此之外,还可以根据实际需求进行更多的配置,如 SSL/TLS 加密、缓存、限流等。
原文地址: https://www.cveoy.top/t/topic/bd38 著作权归作者所有。请勿转载和采集!