nginx配置
2025-03-05
13
# 全局配置 user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # 事件模块 events { worker_connections 1024; use epoll; } # HTTP模块 http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; # 日志格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # 虚拟主机配置 server { listen 80; server_name example.com; access_log /var/log/nginx/access.log main; # 根目录配置 location / { root /usr/share/nginx/html; index index.html index.htm; } # 反向代理配置 location /api/ { proxy_pass http://backend_server; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # 错误页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } # 负载均衡配置 upstream backend_server { server 10.0.0.1:8080 weight=3; server 10.0.0.2:8080; server 10.0.0.3:8080 backup; } } # 静态文件缓存示例 proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m inactive=60m;
本篇文章内容来源于:nginx配置
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。