nginx.conf简单配置
#user nobody;
#nginx的最大进程数,一般和cpu和核心数一致
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#Linux系统使用epoll高效工作模式
#use epoll;
#单个后台worker process进程的最大并发链接数
worker_connections 1024;
}
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;
#用于开启高效文件传输模式
sendfile on;
#开启后,防止网络阻塞
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
#设置客户端连接保持活动的超时时间。在超过这个时间之后,服务器会关闭该连接;
keepalive_timeout 65;
gzip on;
gzip_buffers 16 64k; # 设置gzip申请内存的大小,其作用是按块大小的倍数申请内存空间
gzip_comp_level 4; # 设置gzip压缩等级,等级越底压缩速度越快文件压缩比越小,反之速度越慢文件压缩比越大 [1-9]
gzip_http_version 1.1;
gzip_min_length 1k; # 当返回内容大于此值时才会使用gzip进行压缩,以K为单位,当值为0时,所有页面都进行压缩
gzip_proxied off; # 反向代理时启用
server {
listen 82; #监听端口
server_name localhost 172.16.135.186; #监听ip
#charset koi8-r;
#access_log logs/host.access.log main;
set $rootPath E:/WORK/sxst/src/; #设置变量
root $rootPath; #设置根目录
location / {
root mynginx.com/user/getusers;
index index.html index.htm;
charset utf-8;
}
location ^~ /user/ {
proxy_pass http://mynginx.com/user/;
index index.html index.htm;
charset utf-8;
}
#图片代理
location ^~ /img/ {
alias C:/Users/admin/Pictures/; #alias 所有访问/img/的url,实际访问的是C:/Users/admin/Pictures/;简单说就是,就是访问alias目录地址
autoindex on;
}
#视频代理
location ^~ /video/ {
alias C:/Users/admin/video/;
autoindex on;
}
location ^~ /Pictures/ {
root C:/Users/admin/; #root 指定根目录为C:/Users/admin/,访问Pictures,实际访问的是C:/Users/admin/Pictures/;简单说就是,就是访问root目录与url拼接地址
autoindex on;
}
location ^~ /video/ {
root C:/Users/admin/;
autoindex on;
}
#下载文件
location ^~ /file/ {
alias C:/Users/admin/Downloads/;
#三处配置
client_max_body_size 2048m;
root /home/zhsq/zhsq_plugin/;
concat on;
concat_max_files 20;
}
#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;
#}
}
# 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;
# }
#}
upstream mynginx.com{
#Nginx的负载均衡模块目前支持4种调度算法;
#轮询(默认)每个请求按时间顺序逐一分配到不同的后端服务器,如果后端某台服务器宕机,故障系统被自动剔除,使用户访问不受影响;
#Weight:指定轮询权值,Weight值越大,分配到的访问机率越高,主要用于后端每个服务器性能不均的情况下;
#ip_hash:每个请求按访问IP的hash结果分配,这样来自同一个IP的访客固定访问一个后端服务器,有效解决了动态网页存在的session共享问题;
ip_hash;
server 172.16.135.186:8080;
#server 172.16.135.186:8081;
#server 192.168.8.12:80 down;
#server 192.168.8.13:8009 max_fails=3 fail_timeout=20s;
#server 192.168.8.146:8080;
}
}