【Shell】利用$1,function简化代码

PHP 中文、unicode 互转

  返回  

2021-08-20 记录下 Nginx 反向代理配置

2021/8/20 17:12:22 浏览:

目前代理重定向正则匹配只能处理绝对链接,相对路径还不行

server
{
	listen 0.0.0.0:8080 ssl default_server;
	listen [::]:8080 ssl default_server;

	server_name 127.0.0.1 localhost ~^((?<prefix>.*)?\.)?(?<name>omeo|cobalts|cotools)(\.(?<suffix>.+))$;

	root "${websitedir}";

	index index.php index.html index.htm index.shtml index.xhtml;

	error_page 497 =301 "https://${http_host}${request_uri}";

	location ~ ^(/proxy(.*))
	{
		# https://127.0.0.1:8080/proxy/<https>www.baidu.com/s?word=666
		set $_matches_1 "$1";
		set $_matches_2 "$2";
		set $_proxy_scheme "${scheme}";
		if ($_matches_2 ~* "([^/]+)(.*)")
		{
			set $_proxy_host "$1";
			set $_proxy_path "$2";
		}
		if ($_proxy_host ~* "<(.+)?>(.*)")
		{
			set $_proxy_scheme_ "$1";
			set $_proxy_host "$2";
		}
		if ($_proxy_scheme_)
		{
			set $_proxy_scheme "${_proxy_scheme_}";
		}
		set $_proxy_href "${_proxy_scheme}://${_proxy_host}${_proxy_path}${is_args}${args}";
		add_header X-Proxy-Scheme "${_proxy_scheme}";
		add_header X-Proxy-Host "${_proxy_host}";
		add_header X-Proxy-Path "${_proxy_path}";
		add_header X-Proxy-Href "${_proxy_href}";
		proxy_set_header Host "${_proxy_host}";
		proxy_set_header Accept "${http_accept}";
		proxy_set_header Connection "";
		proxy_set_header X-Real-IP "${remote_addr}";
		proxy_set_header X-Forwarded-For "${proxy_add_x_forwarded_for}";
		proxy_set_header Referer "${http_referer}";
		proxy_set_header Cookie "${http_cookie}";
		proxy_set_header User-Agent "${http_user_agent}";
		proxy_pass_header Set-Cookie;
		proxy_hide_header Vary;
		proxy_ignore_headers Cache-Control Expires;
		proxy_pass "${_proxy_href}";
		proxy_redirect ~([^/:]+)(://)*([^/]+)(.*) "${scheme}://${http_host}/proxy/<$1>$3$4";
	}
}

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号