1、nginx.confB己置文件
注:conf/nginx.conf是nginx的默认配置文件
#运行用户,默认为nginx
user nginx;
#启动进程,通常设置成和cpu的数量相等 worker_processes 1;
error_log /var/log/nginx/logs/error.log; error_log /var/log/nginx/logs/info.log info;
# PID文件,记录当前启动的n ginx的进程ID pid /var/log/nginx/logs/nginx.pid;
#工作模式及连接数上限
#设定日志格式 log_format "$request" ' |
#访问日志 access_log |
on; |
#tcp_nopush |
on; |
http {
#设定支持的媒体类型,类型由m ime .types文件定义 include /var/log/nginx/conf/mime.types;
#二进制流
default_type application/octet-stream;
main '[$remote_addr] - [$remote_user] [$time_local]
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
/var/log/nginx/logs/access.log main;
#sendfile指令指定nginx是否调用sendfile函数(zero copy方式)来输出文件, 对于普通应用,
#必须设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络 I/O处理速度,降低系统的u ptime.
sendfile
on; |
tcp_nodelay
# gzip压缩开关 #gzip on;
upstream yunsuan_server1{
server 127.0.0.1:8080;
server {
#监听80端口,80端口是知名端口号,用于HTTP协议 listen 80;
#域名
server_name www.yunsuan.com;
#首页
index index.html
#指向webapp的目录 root /mnt/app/webapp;
#编码格式
charset utf-8;
#代理配置参数
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_set_header Host $host;//添加发往后端服务器的请求头
proxy_set_header X-Forwarder-For $remote_addr;// 添加发往后端服务器的地 址
#反向代理的路径(和upstream绑定),location后面设置映射的路径 location / {
proxy_pass http://yunsuan_server1;
#静态文件
location ~ 八/(images|javascript|js|css|flash|media|static)/ { root /mnt/app/webapp/views;
#过期30天,如果频繁更新,则可以设置得小一点。 expires 30d;
on; on; "NginxStatus"; conf/htpasswd; |
#禁止访问.htxxx文件 location ~ /\.ht { deny all;
#错误处理页面(可选择性配置)
#error_page 404 |
#error_page |
500 502 503 504 |
/404.html; |
/50x.html; |
#location = /50x.html { # root html;
#}
types {
html htm shtml; |
css; |
text/html
text/css
text/xml | xml; |
image/gif | gif; |
image/jpeg | jpeg jpg; |
application/javascript | js; |
application/atom+xml | atom; |
application/rss+xml | rss; |
text/mathml | mml; |
text/plain | txt; |
text/vnd.sun.j2me.app-descriptor | jad; |
text/vnd.wap.wml | wml; |
text/x-component | htc; |
image/png | png; |
image/tiff | tif tiff; |
image/vnd.wap.wbmp | wbmp; |
image/x-icon | ico; |
image/x-jng | jng; |
image/x-ms-bmp | bmp; |
image/svg+xml | svg svgz; |
image/webp | webp; |
application/font-woff | woff; |
application/java-archive | jar war ear; |
application/json | json; |
application/mac-binhex40 | hqx; |
application/msword | doc; |
application/pdf | pdf; |
application/postscript | ps eps ai; |
application/rtf | rtf; |
application/vnd.apple.mpegurl | m3u8; |
application/vnd.ms-excel | xls; |
application/vnd.ms-fontobject | eot; |
application/vnd.ms-powerpoint | ppt; |
application/vnd.wap.wmlc | wmlc; |
application/vnd.google-earth.kml+xml | kml; |
application/vnd.google-earth.kmz | kmz; |
application/x-7z-compressed | 7z; |
application/x-cocoa | cco; |
application/x-java-archive-diff | jardiff; |
application/x-java-jnlp-file | jnlp; |
application/x-makeself | run; |
application/x-perl | pl pm; |
application/x-pilot | prc pdb; |
application/x-rar-compressed | rar; |
application/x-redhat-package-manager | rpm; |
application/x-sea | sea; |
application/x-shockwave-flash | swf; |
application/x-stuffit | sit; |
application/x-tcl | tcl tk; |
application/x-x509-ca-cert | der pem crt; |
application/x-xpinstall | xpi; |
application/xhtml+xml | xhtml; |
application/xspf+xml | xspf; |
application/zip | zip; |
application/octet-stream | bin exe dll; |
application/octet-stream | deb; |
application/octet-stream | dmg; |
application/octet-stream | iso img; |
application/octet-stream | msi msp msm; |
application/vnd.openxmlformats-officedocument.wordprocessingml.document | |
docx; | |
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | |
xlsx; | |
application/vnd.openxmlformats- | |
officedocument.presentationml.presentation pptx; | |
audio/midi | mid midi kar; |
audio/mpeg | mp3; |
audio/ogg | ogg; |
audio/x-m4a | m4a; |
audio/x-realaudio | ra; |
video/3gpp | 3gpp 3gp; |
video/mp2t | ts; |
video/mp4 | mp4; |
video/mpeg | mpeg mpg; |
video/quicktime | mov; |
video/webm | webm; |
video/x-flv | flv; |
video/x-m4v | m4v; |
video/x-mng | mng; |
video/x-ms-asf | asx asf; |
video/x-ms-wmv | wmv; |
video/x-msvideo | avi; |
3、log_format具体可设置的参数格式
参数 | 说明 | 示例 |
$remote_addr | 客户端地址 | 192.168.10.162 |
$remote_user | 客户端用户名称 | -- |
$time_local | 访问时间和时区 | 18 /Jul/2019 :17:00:01 +0800 |
$request | 请求的URI和HTTP协议 | "GET /article-10000.html HTTP/1.1" |
$http_host | 请求地址IP或域名) | www.yunsuancom 192.168.10.162 |
$status | HTTP请求状态 | 200 |
$upstream_status | upstream 状态 | 200 |
$body_bytes_sent | 发送给客户端文件内容大小 | 1547 |
$http_referer | url跳转来源 | |
$http_user_agent | 用户终端浏览器等信息 | "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; |
$ssl_protocol | SSL协议版本 | TLSv1 |
$ssl_cipher | 交换数据中的算法 | RC4-SHA |
$upstream_addr | 后台upstream的地址,即真 正提供服务的主机地址 | 192.168.10.162:80 |
$request_time | 整个请求的总时间 | 0.205 |
$upstream_response_time | 请求过程中,upstream响应 时间 | 0.002 |