<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nginx &#8211; Microholmes&#039;s Blog</title>
	<atom:link href="https://www.microholmes.com/category/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.microholmes.com</link>
	<description>我的知识分享</description>
	<lastBuildDate>Sun, 28 Nov 2021 16:05:26 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Nginx – 五、实用代理之proxy_cookie_domain</title>
		<link>https://www.microholmes.com/2020/12/15/nginx-%e4%ba%94%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_cookie_domain/</link>
					<comments>https://www.microholmes.com/2020/12/15/nginx-%e4%ba%94%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_cookie_domain/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Tue, 15 Dec 2020 14:51:34 +0000</pubDate>
				<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=168</guid>

					<description><![CDATA[在使用nginx进行反向代理不同域名站点时，cookie也需要进行替换，才能被写入到浏览器中。通常在代理一些身 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>在使用nginx进行反向代理不同域名站点时，cookie也需要进行替换，才能被写入到浏览器中。通常在代理一些身份认证的站点时需要，如sso(单点登录)。</p>



<p>如xyz.test.com的域名，代理192.168.1.100，如不处理的话，仍然会返回path=192.168.1.100的cookie，而此时的请求地址是https://xyz.test.com，cookie是无法写入的。</p>



<p>当使用proxy_cookie_domain进行转换后，会将cookie的path替换成xyz.test.com，此时就可以顺利写入cookie了。</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>server {
  listen       443 ssl;
  server_name  xyz.test.com;

  ssl_certificate      cert/_test_com.pem;
  ssl_certificate_key  cert/_test_com.key;

  location / {
    proxy_cookie_domain 192.168.1.100 xyz.test.com;
    proxy_pass http://192.168.1.100/;
  }
}</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/12/15/nginx-%e4%ba%94%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_cookie_domain/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nginx – 四、实用代理之sub_filter</title>
		<link>https://www.microholmes.com/2020/12/12/nginx-%e5%9b%9b%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bsub_filter/</link>
					<comments>https://www.microholmes.com/2020/12/12/nginx-%e5%9b%9b%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bsub_filter/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Sat, 12 Dec 2020 15:18:39 +0000</pubDate>
				<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=140</guid>

					<description><![CDATA[sub_filter支持将返回内容（response body）中的内容进行替换。如返回内容中有跳转地址，比如 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>sub_filter支持将返回内容（response body）中的内容进行替换。如返回内容中有跳转地址，比如一些302跳转不是直接通过请求头中的Location，而是由表单自动提交的form，可将返回内容先进行替换，如把http://192.168.1.100更换为https://xyz.test.com，这样就方便地修改代理的跳转地址，不用修改代码。</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>sub_filter 'http://192.168.1.100' 'https://xyz.test.com';</pre></div>



<p>参考完整实例：</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>server {
  listen       443 ssl;
  server_name  xyz.test.com;
  ssl_certificate      cert/_test_com.pem;
  ssl_certificate_key  cert/_test_com.key;
  location / {
    proxy_redirect ~^http://192.168.1.100/(.*) https://xyz.test.com/$1;
    proxy_pass http://192.168.1.100/;
    sub_filter 'http://192.168.1.100' 'https://xyz.test.com';
    sub_filter_once off;
  }
}</pre></div>



<p>sub_filter_once on | off。默认: on，只执行一次。sub_filter指令是执行一次，还是重复执行。</p>



<h4 class="wp-block-heading">不生效处理办法</h4>



<p>增加配置：</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>proxy_set_header Accept-Encoding &quot;&quot;;</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/12/12/nginx-%e5%9b%9b%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bsub_filter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nginx – 三、实用代理之proxy_redirect</title>
		<link>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%89%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_redirect/</link>
					<comments>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%89%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_redirect/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 13:49:50 +0000</pubDate>
				<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=138</guid>

					<description><![CDATA[proxy_redirect支持将返回头（response header）中的Location内容进行替换。请 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>proxy_redirect支持将返回头（response header）中的Location内容进行替换。请求头中的Location字段是302跳转的地址，浏览器会自动跳转到该字段配置的地址。</p>


<div class="wp-block-codemirror-blocks-code-block code-block"><pre>server {
  listen       443 ssl;
  server_name  xyz.test.com;

  ssl_certificate      cert/_test_com.pem;
  ssl_certificate_key  cert/_test_com.key;

  location / {
    proxy_redirect ~^http://192.168.1.100/(.*) https://xyz.test.com/$1;
    proxy_pass http://192.168.1.100/;
  }
}</pre></div>



<p>通常反向代理后，原网站的一些302跳转地址还是原来代理的地址（本文中指192.168.1.100），此时如果不想改动代码配置，可通过给nginx增加proxy_rediret配置，来替换location中的地址。</p>



<p>如原location为：http://192.168.1.100/index.html，可配置：</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>proxy_redirect ~^http://192.168.1.100/(.*) https://xyz.test.com/$1;</pre></div>



<p>配置后，访问后得到的地址会是：https://xyz.test.com/index.html。其中“~^”是使用正则的标志，“(.*)”表示其他内容，nginx自动填充到后面对应的“$1”中，如果有多个“(.*)”，则依次填写“$1”，“$2”，依次类推。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%89%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bproxy_redirect/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nginx – 二、实用代理之https</title>
		<link>https://www.microholmes.com/2020/12/08/nginx-%e4%ba%8c%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bhttps/</link>
					<comments>https://www.microholmes.com/2020/12/08/nginx-%e4%ba%8c%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bhttps/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 13:36:52 +0000</pubDate>
				<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=136</guid>

					<description><![CDATA[nginx可把http的站点反向代理为https的站点，只需要在nginx上配置对应的证书，及监听对应的端口。 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>nginx可把http的站点反向代理为https的站点，只需要在nginx上配置对应的证书，及监听对应的端口。</p>



<p>nginx也支持配置http2.0，具体配置可参考官方网站介绍或其他博客介绍。</p>



<p>以下展示nginx反向代理为https站点：<br>你必须具备以下物料：<br>1. 一个域名，如xyz.test.com;<br>2. 这个域名对应的证书，通常为pfx格式的证书，可通过openssl工具将其解析成pem和key两个证书文件；<br>3. 如需要浏览器认可证书，需要购买认可的ca证书，自己颁发的私有证书，现在的chrome浏览器（版本87.0.4280.88）通常会提示不安全，并拒绝访问，需要用户点击确认访问。</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre>server {
  listen 443 ssl;
  server_name xyz.test.com;

  ssl_certificate cert/_test_com.pem;
  ssl_certificate_key cert/_test_com.key;

  location / {
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://192.168.1.100/;

  sub_filter_once off;
  }
}</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/12/08/nginx-%e4%ba%8c%e3%80%81%e5%ae%9e%e7%94%a8%e4%bb%a3%e7%90%86%e4%b9%8bhttps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nginx &#8211; 一、基本代理</title>
		<link>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%80%e3%80%81%e5%9f%ba%e6%9c%ac%e4%bb%a3%e7%90%86/</link>
					<comments>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%80%e3%80%81%e5%9f%ba%e6%9c%ac%e4%bb%a3%e7%90%86/#respond</comments>
		
		<dc:creator><![CDATA[Microholmes]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 13:21:32 +0000</pubDate>
				<category><![CDATA[Nginx]]></category>
		<guid isPermaLink="false">http://www.microholmes.com/?p=133</guid>

					<description><![CDATA[nginx基本反向代理，常用于将内网站点代理开放给外网访问。 如外网https://xyz.test.com， [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>nginx基本反向代理，常用于将内网站点代理开放给外网访问。</p>
<p>如外网https://xyz.test.com，内网是http://192.168.1.100，代理如下:</p>


<div class="wp-block-codemirror-blocks-code-block code-block"><pre>server {
  listen       443 ssl;
  server_name  xyz.test.com;

  ssl_certificate      cert/_test_com.pem;
  ssl_certificate_key  cert/_test_com.key;

  location / {
    proxy_pass http://192.168.1.100/;
  }
}</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.microholmes.com/2020/12/08/nginx-%e4%b8%80%e3%80%81%e5%9f%ba%e6%9c%ac%e4%bb%a3%e7%90%86/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
