nginx的主配置(nginx.conf)说明
#worker进程数量
worker_processes 1;
#错误日志
error_log logs/error.log;
#进程ID文件
pid logs/nginx.pid; #事件区块开始
events {
#worker进程支持的最大连接数
worker_connections 1024;
} #http区块开始
http {
#nginx支持的媒体类型库文件
include mime.types;
#默认的媒体文件
default_type application/octet-stream;
#开启高效传输模式
sendfile on;
#连接超时
keepalive_timeout 65; #一个server区块开始
server {
#端口号
listen 80;
#服务主机名
server_name localhost;
#编码
charset utf-8;
#location区块
location / {
#站点根目录
root html;
#默认首页文件
index index.html index.htm;
}
#出现对应状态码时,访问50x.html
error_page 500 502 503 504 /50x.html;
#访问50x.html时指定目录为html
location = /50x.html {
root html;
}
}
}
nginx的状态信息功能
location / {
#打开状态信息开关
stub_status on;
access_log off;
allow 127.0.0.1/24;
deny all;
}
nginx错误日志配置
关键字 日志文件 错误日志级别[debug|info|notice|warn|error|crit|alert|emerg]
error_log logs/error.log notice;
nginx访问日志配置
#定义日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#格式参数说明
参数 | 说明 | 示例 |
$remote_addr | 客户端地址 | 211.28.65.253 |
$remote_user | 客户端用户名称 | -- |
$time_local | 访问时间和时区 | 18/Jul/2012:17:00:01 +0800 |
$request | 请求的URI和HTTP协议 | "GET /article-10000.html HTTP/1.1" |
$http_host | 请求地址,即浏览器中你输入的地址(IP或域名) | www.it300.com 192.168.100.100 |
$status | HTTP请求状态 | 200 |
$upstream_status | upstream状态 | 200 |
$body_bytes_sent | 发送给客户端文件内容大小 | 1547 |
$http_referer | url跳转来源 | https://www.baidu.com/ |
$http_user_agent | 用户终端浏览器等信息 | "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; GTB7.0; .NET4.0C; |
$ssl_protocol | SSL协议版本 | TLSv1 |
$ssl_cipher | 交换数据中的算法 | RC4-SHA |
$upstream_addr | 后台upstream的地址,即真正提供服务的主机地址 | 10.10.10.100:80 |
$request_time | 整个请求的总时间 | 0.205 |
$upstream_response_time | 请求过程中,upstream响应时间 | 0.002 |
#访问日志配置
access_log logs/access.log main;
#在高并发的网站下,日志配置可以如下
access_log logs/access.log main gzip buffer=32k flush=5s;
nginx的location作用
location的作用是根据用户请求的URI来执行不同的应用。
location [= | ~ | ~* | ^~] URI {
... ...
}
~用于区分大小写
~*用于不区分大小写
^~进行常规字符串匹配检查后,不做正则表达式的检查
例如:
location = / {
#精确匹配/
}
location / {
#所有location不能匹配后的默认匹配
}
location /www/ {
#匹配常规字符串,有正则,优先匹配正则
}
location ^~ /imgs/ {
#匹配常规字符串,不做正则匹配检查
}
location ~* \.(gif|jpg|jpeg)$ {
#正则匹配
}
nginx的rewrite配置
rewrite指令语法
rewrite regex replacement [flag];
例如:
rewrite ^/(.*) http://www.baidu.com/$1 permanent;
其中$1表示前面小括号匹配的部分。
flag参数说明:
last 本条规则匹配完成后,继续向下匹配新的规则
break 本条规则匹配完即终止
redirect 返回302临时重定向
permanent 返回301永久重定向
上述,last和break用来实现URL重写,redirect和permanet用来实现URL跳转
例如:
server {
listen 80;
server_name book.site.com;
location / {
root html/book;
index index.html index.htm;
}
if($http_host ~* "^(.*)\.site\.com$") {
set $domain $1;
rewrite ^(.*) http://www.site.com/$domain/test.html break;
}
}
当我们访问book.site.com时URL重写为www.site.com/book/test.html
nginx常用配置说明的更多相关文章
-
nginx 常用配置说明
一.location 配置 1.1 语法规则: location [=|~|~*|^~] /uri/ { … }= 开头表示精确匹配^~ 开头表示uri以某个常规字符串开头,理解为匹配 url路径即可 ...
-
170816、nginx常用配置说明
#user nobody; #开启进程数 <=CPU数 worker_processes 1; #错误日志保存位置 #error_log logs/error.log; #error_log ...
-
nginx的重试机制以及nginx常用的超时配置说明
nginx的重试机制 现在对外服务的网站,很少只使用一个服务节点,而是部署多台服务器,上层通过一定机制保证容错和负载均衡. nginx就是常用的一种HTTP和反向代理服务器,支持容错和负载均衡. ng ...
-
【Linux】nginx常用命令
相关内容链接 Centos之安装Nginx及注意事项 [nginx]详细配置说明 nginx常用命令 [重新加载配置]sudo nginx -s reload [打开nginx配置]sudo vim ...
-
Nginx常用功能配置一
Nginx常用功能配置 参数include配置 说明:如果日常工作中server标签存在太多,可以采用include配置模式,Nginx的主配置文件包含的所有虚拟主机的子配置文件会统一放入extra目 ...
-
Nginx 常用全局变量 及Rewrite规则详解
每次都很容易忘记Nginx的变量,下面列出来了一些常用 $remote_addr //获取客户端ip $binary_remote_addr //客户端ip(二进制) $remote_port //客 ...
-
nginx 常用的 URL 重写方法
转自:http://www.jbxue.com/article/4727.html Nginx中一些常用的URL 重写方法介绍,有需要的朋友可以参考下.url重写应该不陌生,不管是SEO URL 伪静 ...
-
3.Nginx常用功能介绍
Nginx常用功能介绍 Nginx反向代理应用实例 反向代理(Reverse Proxy)方式是指通过代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器,并且从内部网络服 ...
-
Nginx常用配置实例(4)
Nginx作为一个HTTP服务器,在功能实现方面和性能方面都表现得非常卓越,完全可以与Apache相媲美,几乎可以实现Apache的所有功能,下面就介绍一些Nginx常用的配置实例,具体包含虚拟主机配 ...
随机推荐
-
《Python标准库》 目录
目录 译者序序前言第1章 文本1.1 string—文本常量和模板1.1.1 函数1.1.2 模板1.1.3 高级模板1.2 textwrap—格式化文本段落1.2.1 示例数据1.2.2 填充段落1 ...
-
WPFINotifyPropertyChanged使用技巧
WPFINotifyPropertyChanged使用技巧 public class NotifyPropertyChanged : INotifyPropertyChanged { public e ...
-
Delphi XE5教程5:程序的结构和语法
内容源自Delphi XE5 UPDATE 2官方帮助<Delphi Reference>,本人水平有限,欢迎各位高人修正相关错误! 也欢迎各位加入到Delphi学习资料汉化中来,有兴趣者 ...
-
【转】getopt模块,实现获取命令行参数
python中 getopt 模块,该模块是专门用来处理命令行参数的 函数getopt(args, shortopts, longopts = []) 参数args一般是sys.argv[1:],sh ...
-
HTTP 404 Not Found Error with .woff or .woff2 Font Files
如果是 ERR_ABORTED 404 (Not Found) WOFF2,则有可能是文件不存在
-
localStorage,sessionStorage和cookie的区别
sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...
-
ProtonMiner挖矿蠕虫
特征 ProtonMail邮箱地址 利用漏洞 服务 漏洞 Hadoop 未授权访问 Drupal CVE-2018-7600 Redis 未授权访问 Spring Data Commons CVE-2 ...
-
ping 返回的TTL数值代表什么?
ping 返回的TTL数值代表什么? 1 [root@standby ~]# dig @202.106.0.20 www.iqiyi.com 2 3 ; <<>> DiG 9. ...
-
日期时间函数 mysql 和sqlserver 中对于常用函数的日期和时间函数的区别
1. sqlserver中获取时间用getdate(),默认返回格式是2019-01-21 13:58:33.053,具体的年月日,时分秒毫米,年月日之间用短线连接,时分秒之间用冒号连接,秒和毫米之间 ...
-
php单点登陆简单实现 (iframe方式)
有四个网站分别为: www.a.com www.b.com www.c.com www.sso.com 需求是如果我们在sso登陆后,其他网站也会显示登陆中,不需要重复登陆,退出时,其他网站也会失效. ...