码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx

时间:2019-03-17 23:33:59      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:nginx配置文件   remote   user   listen   com   转换   虚拟主机   允许   $1   

1 .基于rewrite实现全站https 
server {
  listen 192.168.1.111:80;
  server_name test.com;
  rewrite ^(.*)$ https://$host$1 permanent;
  }
  搭建此虚拟主机完成后,就可以将http://test.com的请求全部重写到https://test.com上了
  nginx的497状态码
  error code 497
  497 - normal request was sent to HTTPS
  解释:当此虚拟站点只允许https访问时,当用http访问时nginx会报出497错误码
2.自定义nginx访问日志,转换成json格式,熟悉日志中变量的作用
1>修改nginx的配置文件nginx.conf

log_format  json  ‘{"@timestamp":"$time_iso8601",‘
                  ‘"@version":"1",‘
                  ‘"client":"$remote_addr",‘
                  ‘"url":"$uri",‘
                  ‘"status":"$status",‘
                  ‘"domain":"$host",‘
                  ‘"host":"$server_addr",‘
                  ‘"size":"$body_bytes_sent",‘
                  ‘"responsentime":"$request_time",‘
                  ‘"referer":"$http_referer",‘
                  ‘"useragent":"$http_user_agent",‘
                  ‘"upstreampstatus":"$upstream_status",‘
                  ‘"upstreamaddr":"$upstream_addr",‘
                  ‘"upstreamresponsetime":"$upstream_response_time"‘
                   ‘}‘;

access_log  logs/access_json.log  json;

#将以上内容添加到nginx配置文件的http区块123456789101112131415161718

2>、输入的日志格式如下:

{"@timestamp":"2019-03-16T00:44:07+08:00","@version":"1","client":"192.168.1.X","url":"-","status":"400","domain":"localhost","host":"192.168.1.x","size":"166","responsentime":"0.286","referer":"-","useragent":"-","upstreampstatus":"-","upstreamaddr":"-","upstreamresponsetime":"-"}br/>{"@timestamp":"2019-03-16T22:02:29+08:00","@version":"1","client":"192.168.1.x","url":"-","status":"400","domain":"localhost","host":"192.168.1.x","size":"166","responsentime":"0.205","referer":"-","useragent":"-","upstreampstatus":"-","upstreamaddr":"-","upstreamresponsetime":"-"}
{"@timestamp":"2019-03-16T22:02:29+08:00","@version":"1","client":"192.168.1.x","url":"-","status":"400","domain":"localhost","host":"192.168.1.x","size":"166","responsentime":"0.218","referer":"-","useragent":"-","upstreampstatus":"-","upstreamaddr":"-","upstreamresponsetime":"-"}123

3>、输出的json格式为:

{
"@timestamp": "2019-03-16T22:02:29+08:00",
"@version": "1",
"client": "192.168.1.x",
"url": "-",
"status": "400",
"domain": "localhost",
"host": "192.168.1.x",
"size": "166",
"responsentime": "0.218",
"referer": "-",
"useragent": "-",
"upstreampstatus": "-",
"upstreamaddr": "-",
"upstreamresponsetime": "-"
}
3.基于location实现将访问web的请求转发至后端apache服务器,最好实现cache功能

Nginx

标签:nginx配置文件   remote   user   listen   com   转换   虚拟主机   允许   $1   

原文地址:https://blog.51cto.com/14127448/2364343

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!