首页 > 系统相关 >NGINX

NGINX

时间:2024-08-01 16:10:22浏览次数:7  
标签:index 匹配 server NGINX html location error

1. 核心概念理解

#location匹配命令
#	~   表示执行一个正则匹配,区分大小写
#	~* 表示执行一个正则匹配,不区分大小写
#	^~ 表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录
#	=    进行普通字符精确匹配
#	@   定义一个命名的location,使用在内部定向时,例如 error_page, try_files
#	 
#	=前缀的指令严格匹配这个查询。如果找到,停止搜索。
#	所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。
#	正则表达式,在配置文件中定义的顺序。
#	如果第3条规则产生匹配的话,结果被使用。否则,如同从第2条规则被使用。
#	 
#	location 匹配的优先级(与location在配置文件中的顺序无关)
#	= 精确匹配会第一个被处理。如果发现精确匹配,nginx停止搜索其他匹配。
#	普通字符匹配,正则表达式规则和长的块规则将被优先和查询匹配,也就是说如果该项匹配还需去看有没有正则表达式匹配和更长的匹配。
#	^~ 则只匹配该规则,nginx停止搜索其他匹配,否则nginx会继续处理其他location指令。
#	最后匹配理带有"~"和"~*"的指令,如果找到相应的匹配,则nginx停止搜索其他匹配;当没有正则表达式或者没有正则表达式被匹配的情况下,那么匹配程度最高的逐字匹配指令会被使用。
#	location = / {                     # 只匹配"/".
#	[ configuration A ]
#	}
#	 
#	location / {                        # 匹配任何请求,因为所有请求都是以"/"开始,但是更长字符匹配或者正则表达式匹配会优先匹配
#	[ configuration B ]
#	}
#	 
#	location ^~ /images/ {           # 匹配任何以 /images/ 开始的请求,并停止匹配 其它location
#	[ configuration C ]
#	}
#	 
#	location ~* \.(gif|jpg|jpeg)$ {         # 匹配以 gif, jpg, or jpeg结尾的请求. 但是所有 /images/ 目录的请求将由 [Configuration C]处理.
#	[ configuration D ]
#	}

2.配置实际使用




#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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;
	
	
	
	
	# 简单文件服务下载功能,本地文件可以下载
	#autoindex on;# 显示目录
	#autoindex_exact_size on;# 显示文件大小
	#autoindex_localtime on;# 显示文件时间
    #sendfile        on;  # 高效传输文件0拷贝
	#server {
	#	charset      utf-8,gbk; 
	#	listen       9050 default_server;
	#	listen       [::]:9050 default_server;
	#	server_name  _;
	#	root         D:\\test\\;
	#	location / {
	#		if ( $request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt)$){
	#			add_header Content-Disposition attachment;
	#			add_header Content-Type application/octet-stream;
	#		}
	#	}
	#}
	
	
	# 图片文件预览功能,jpg可以预览,png预览为乱码
    #server {
    #    listen       8088;
    #    server_name  localhost;# 域名为localhost
	#	charset      utf-8,gbk; 
	#	
    #    location / {
    #        root   D:\\test\\nginx-1.18.0\\picture\\;
    #        index  index.html index.htm;
	#		if ( $request_filename ~* ^.*?\.(doc|zip|docx|txt)$){
	#			add_header Content-Disposition attachment;
	#			add_header Content-Type application/octet-stream;
	#		}
    #    }
	#
    #    error_page   500 502 503 504  /50x.html;
    #    location = /50x.html {
    #        root   html;
    #    }
	#
    #}
	
	#HTTP服务器
    #server {
    #    #监听80端口,80端口是知名端口号,用于HTTP协议
    #    listen       80;
    #    #定义使用www.xx.com访问需要hosts配置
    #    server_name  localhost;
	#	#首页
	#	index index.html
	#	#指向webapp的目录
	#	root D:\\workspace\\spring-shiro\\src\\main\\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://zp_server1;
    #    }
	#
    #    #静态文件,nginx自己处理,re 匹配开头
    #    location ~ ^/(images|javascript|js|css|flash|media|static)/ {
    #        root D:\\spring-shiro\\src\\main\\webapp\\views;
    #        #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
    #        expires 30d;
    #    }
	#
    #    #设定查看Nginx状态的地址
    #    location /NginxStatus {
    #        stub_status           on;
    #        access_log            on;
    #        auth_basic            "NginxStatus";
    #        auth_basic_user_file  conf/htpasswd;
    #    }
	#
    #    #禁止访问白名单设计,ip  
    #    location ~ /api/{
    #        deny 10.11.110.20;
	#		deny 10.11.110.30;
	#		allow 10.1.1.9;
	#		allow 10.8.76.4;
	#		deny all;
    #    }
	#
	#	#错误处理页面(可选择性配置)
	#	#error_page   404              /404.html;
	#	#error_page   500 502 503 504  /50x.html;
    #    #location = /50x.html {
    #    #    root   html;
    #    #}
    #}

	#server {
    #    listen       8088;
    #    server_name  localhost;# 域名为localhost
	#	charset      utf-8,gbk; 
	#	
    #    location / {
    #        root   D:\\test\\nginx-1.18.0\\picture\\;
    #        index  index.html index.htm;
	#		# 下载为文件的配置
	#		if ( $request_filename ~* ^.*?\.(doc|zip|docx|txt)$){
	#			add_header Content-Disposition attachment;
	#			add_header Content-Type application/octet-stream;
	#		}
    #    }
	#
    #    error_page   500 502 503 504  /50x.html;
    #    location = /50x.html {
    #        root   html;
    #    }
	#
    #}


    # 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;
    #    }
    #}

}


https://github.com/dunwu/nginx-tutorial

标签:index,匹配,server,NGINX,html,location,error
From: https://www.cnblogs.com/hbym/p/18336845

相关文章

  • zabbix应用教程:基于Nginx页面响应的日志监控用例
    作者乐维社区(forum.lwops.cn)许远背景:某公司基于Nginx服务器搭建的网站,需要监控页面响应耗时的数据,因此该公司搭建了zabbix开源监控系统,当监控到页面响应时间超过3000ms阈值时,就进行告警通知。本文将通过日志关键字的监控来实现对页面响应时间感知,示例Zabbix版本:5.0.9。日志文......
  • 内网穿透公众号开本地nginx发环境配置(花生壳和量子互联)
    昨天搞了一天,这儿总结一下,免得以后忘了 nginx收入80端口  所以穿透的工具局域网设80    其它端口根据软件应用配置花生壳的通道要选https  量子互联的话tcp配置启动https就可以nginx 我用1.24没有能成功  1.20成功了,不知道啥原因nginx配置时注意全文,都......
  • 02.Nginx的安装与Dockerfile的编写
    获取nginx安装包地址:https://nginx.org/en/download.htmlMainlineversion:Mainline是Nginx目前主力在做的版本,可以说是开发版Stableversion:最新稳定版,生产环境上建议使用的版本Legacyversions:遗留的老版本的稳定版我们下载linux上的安装包tar.gz结尾的,右键复制链接即......
  • nginx配置
    nginx配置安装nginx‍安装所需插件yum-yinstallgccyuminstall-ypcrepcre-develinstall-yzlibzlib-develyuminstall-yopensslopenssl-devel下载安装包编译或上传nginx-1.26.1.tar.gzwgethttps://nginx.org/download/nginx-1.26.1.tar.gztar-xzfng......
  • 借助 NGINX 对本地的 Kubernetes 服务进行自动化的 TCP 负载均衡
    原文作者:ChrisAkker-F5技术解决方案架构师,SteveWagner-F5NGINX解决方案架构师原文链接:借助NGINX对本地的Kubernetes服务进行自动化的TCP负载均衡转载来源:NGINX中文官网NGINX唯一中文官方社区,尽在 nginx.org.cn作为一名现代应用开发人员,您不仅使用一......
  • [SUCTF 2019]Pythonginx (unicode转IDNA域名分割漏洞)
    代码我看到这两个就感觉有问题了,第一个转编码这个搜了一下是unicode转idna的问题,第二个urlopen是Python标准库中urllib.request模块中的一个函数,用于向指定的URL发送HTTP请求并获取响应参考文章:https://xz.aliyun.com/t/6070?time__1311=n4%2BxnD0DgDcmG%3DrDsYoxCqiIQ7KDtH......
  • Nginx最简学习网站——Nginx 极简教程
    教程地址https://dunwu.github.io/nginx-tutorial/#/nginx-quickstart以配置静态站点为例worker_processes1;events{worker_connections1024;}http{includemime.types;default_typeapplication/octet-stream;sendfileon;......
  • 奶奶都能学会的Linux系统nginx安装详细过程
    nginx安装安装前准备下载nginx源码包编译安装服务优化控制命令编辑网站首页访问验证Nginx的优点包括:性能高效,适合高并发环境资源消耗低,适合资源受限的环境配置简单,易于理解和修改轻量级,占用较少内存可靠性高,长时间运行中保持稳定性安装前准备1.依赖下载[root......
  • nginx 配置
    编辑Nginx配置文件:linux:Nginx的配置文件通常位于/etc/nginx/nginx.conf,但也可能在/etc/nginx/conf.d/目录下的某个文件中windows:打开文件夹找到nginx.conf文件1:配置普通的ip端口转发:只需新增server模块 server{ listen4210;#配置负载均衡服务器......
  • Nginx 如何代理转发传递真实 ip 地址?
    Nginx是一个高性能的反向代理服务器,也是一个非常流行的负载均衡器和HTTP缓存。其轻量级的设计和高并发处理能力使得它广泛应用于各种Web服务中。在使用Nginx作为反向代理服务器时,一个常见的问题是如何在代理转发过程中传递客户端的真实IP地址。默认情况下,Nginx会......