nginx 配置文件详解

nginx.conf 主要配置信息

http{
	server{
#		listen IP:port
#		listen *:IP
		listen 127.0.0.1:80;
		
		server_name _;		#默认匹配
		location / {	#URL访问路径匹配,可以多个location
			index index.php;
			root html;	#nginx 安装路径 相对路径	
		}
		location = / {
				
		}
	}

	server{

		location / {	#URL访问路径匹配,可以多个location
				
		}
	}
}

==================================================================


location :


location:不同资源请求的路径
location [= | ~ | ~* | ^~ | @ ]


= : 精确匹配
   比如 /bbs 
   不加 = ,则表示bbs下所有文件目录,包括子目录
   加 = ,仅表示bbs下的文件,不包括子目录


^~ : 禁止匹配正则表达式


~ : 正则表达式,模式匹配,区分字符大小写
~*:正则表达式,模式匹配,不区分字符大小写


location / {
RA : 匹配 / 下面所有文件,包括子目录
}


location = /{
RB : 只匹配 / 目录本身,不包括子目录
}


location ^~ /images/{
RC
}


location ~* \.(gif|jpg|jpeg)$ {
RD
}


1. / ==>> RB
2. /a/b/c ==>> RA
3. /images/gif ==>> RC
4. /documents/1.jpg ==>> RD


==================================================================


root:


root path 
在server中:表示全局的,对所有有的location都有意义。
在location:局部的资源定义
location /a/ {
root /var/www/;
}
location / 就代表 location 里面的 root,若是location里的 root 未定义,就从 server 里面继承!
/a/1.html = /var/www/a/1.html


==================================================================


alias:


location ~ ^/images/(.*)${
alias /var/www/files/$1
}


URI: /images/1.txt ==>> /var/www/files/1.txt




location /i/ {
alias /var/www/
}
URI : /i/1.html ==>> /var/www/1.html


==================================================================

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值