
nginx配置详解
发布日期:2025-04-20 23:31:49
浏览次数:8
分类:精选文章
本文共 2329 字,大约阅读时间需要 7 分钟。
Nginx 全局配置
1. 用户和进程数配置
user www www;worker_processes 8;
2. 错误日志和进程文件
error_log /var/log/nginx/error.log info;pid /var/run/nginx.pid;
3. 文件和连接限制
worker_rlimit_nofile 65535;events { use epoll;}worker_connections 65535;
4. FastCGI 配置
fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;
5. Gzip 配置
gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml;gzip_vary on;
6. 负载均衡配置
upstream blog.ha97.com { server 192.168.80.121:80 weight=3; server 192.168.80.122:80 weight=2; server 192.168.80.123:80 weight=3;}
7. 虚拟主机配置
http { server { listen 80; server_name www.ha97.com 192.168.1.12; index index.html index.htm index.php; root /data/www/ha97; location ~ .*\.(php|php5)? { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 10d; } location ~ .*\.(js|css)? { expires 1h; } location / { proxy_pass http://127.0.0.1:88; 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; } }}
8. 日志格式
log_format access '$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/ha97access.log access;
9. 状态监控
location /NginxStatus { stub_status on; access_log on; auth_basic "NginxStatus"; auth_basic_user_file conf/htpasswd;}
10. 本地静态分离反向代理
location ~ .(jsp|jspx|do)?{ 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:8080;}
11. 静态文件缓存
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)?{ expires 15d;}location ~ .*.(js|css)?{ expires 1h;}
发表评论
最新留言
不错!
[***.144.177.141]2025年04月21日 15时20分48秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!