nginx配置文件nginx.conf
2017-09-13 00:00
501 查看
这里使用 nginx负载两个tomcat服务
nginx.conf文件
#user nobody;#windows 不配置 #工作的子进程数量(通常等于CPU数量或者2倍于CPU) worker_processes 8; #错误日志存放路径,默认地址在nginx路径下的logs下 #error_log logs/error.log; #error_log logs/error.log notice; error_log logs/error.log info; #指定pid存放文件 #pid logs/nginx.pid; events { #允许最大连接数 worker_connections 2048; } 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; #keepalive_timeout 0; keepalive_timeout 65; gzip on; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; upstream mytomcat{#mytomcat与 location的 proxy_pass的值对应 ip_hash;#确保每个访问的ip每次sessoion只访问到一个服务 #weigth参数表示权值,权值越高被分配到的几率越大 #server 127.0.0.1:8080 weight=1 ; server 127.0.0.1:8080;#tomcat6 server 127.0.0.1:8888;#tomcat6 } server { listen 80; server_name mpc; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.jsp index.html index.htm; proxy_pass http://mytomcat;#upstream 对应 proxy_set_header Host $host; #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP。 client_max_body_size 10m; #允许客户端请求的最大单文件字节数。 client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数。 proxy_connect_timeout 3; #Nginx跟后端服务器连接超时时间。超时会连接到另外一台服务器 proxy_read_timeout 90; #连接成功后,后端服务器响应时间。 proxy_buffer_size 4k; #设置代理服务器保存用户头信息的缓冲区大小。 proxy_buffers 6 32k; #proxy_buffers缓冲区。 proxy_busy_buffers_size 64k; #高负荷下缓冲大小。 proxy_temp_file_write_size 64k; #设定缓存文件夹大小。 } #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; # } #} }
几个常用命令
start nginx #启动nginx nginx -s quit #关闭nginx 慢慢关闭? nginx -s stop #停止nginx 跟关闭类似,直接关闭? nginx -s reload #修改了配置文件重新加载
定时切割nginx访问日志文件
随着访问量越来越大,nginx的日志文件会不断增大,会导致日志写入时间增加,所以定时备份切割日志文件是必须的,这里写一个windows下定时将日志文件备份情况的命令行:@echo off echo 备份日志文件 #取到当前所有日志文件数量 for /f %%i in ('dir *.log /b/a-d') do set /a num+=1 #备份日志文件 copy access.log access%num%.log #将一个空日志文件覆盖原来的日志文件 copy /y accessnull.log access.log echo ... echo ... echo 备份完成! #pause
相关文章推荐
- Nginx配置文件(nginx.conf)配置详解
- Nginx的nginx.conf配置文件中文注释说明
- Nginx配置文件nginx.conf详解
- Nginx(二)------nginx.conf 配置文件
- nginx配置文件nginx.conf实例
- Nginx配置文件nginx.conf中文详解
- Nginx配置文件nginx.conf中文详解
- (总结)Nginx配置文件nginx.conf中文详解
- Magento Nginx安全配置conf文件
- Nginx配置文件nginx.conf中文详解
- Nginx 配置文件 nginx.conf 详解
- Nginx配置文件nginx.conf详解(总结)
- Nginx配置文件nginx.conf中文详解(总结)
- Nginx配置文件nginx.conf中文详解
- 生产环境下的nginx.conf配置文件(多虚拟主机)
- Nginx服务器nginx.conf的配置文件说明
- Nginx配置文件(nginx.conf)配置详解
- (总结)Nginx配置文件nginx.conf中文详解GOOD
- Nginx配置文件nginx.conf中文详解
- 比较完整的Nginx配置文件nginx.conf常用参数中文详解