<?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; 科技改变生活-雨落星辰</title>
	<atom:link href="https://p1e.cn/html/tag/nginx/feed" rel="self" type="application/rss+xml" />
	<link>https://p1e.cn</link>
	<description>所有的伟大,都源于一个勇敢的开始</description>
	<lastBuildDate>Wed, 22 Mar 2023 09:17:39 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Nginx服务器接入百度云加速CDN后如何获取真实访客IP？</title>
		<link>https://p1e.cn/html/3400.html</link>
					<comments>https://p1e.cn/html/3400.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Wed, 22 Mar 2023 09:17:39 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[百度CDN]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3400</guid>

					<description><![CDATA[默认情况下，开启百度云加速CDN后，网站日志的请求IP只会显示 百度CDN的代理节点。 但有些站长是需要查看访客真实IP，所以今天教大家如何获取真实用户IP。 百度云加速转发的HTTP头信息中增加 X-Forwarded-For 信息，用于记录客户端的真实IP，所以我们只要修改服务器配置就行， Nginx获取真实IP的方法: 原理:使用Nginx自带的Realip模块获取用户真实IP 修改nginx配置:http{}中添加如下: set_real_ip_from 0.0.0.0/0; real_ip_header]]></description>
										<content:encoded><![CDATA[<p>默认情况下，开启<b>百度云加速</b>CDN后，网站日志的请求IP只会显示 百度CDN的代理节点。</p>
<p>但有些站长是需要查看访客真实IP，所以今天教大家如何获取真实用户IP。</p>
<p>百度云加速转发的HTTP头信息中增加 X-Forwarded-For 信息，用于记录客户端的真实IP，所以我们只要修改服务器配置就行，</p>
<p><b>Nginx</b>获取真实IP的方法:<br />
原理:使用Nginx自带的Realip模块获取用户真实IP<br />
修改nginx配置:http{}中添加如下:</p>
<pre>
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For; 
</pre>
<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" class="lazy entered loaded alignnone size-full wp-image-3401" title="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图" src="https://i.p1e.cn/2023/03/blog20230322171618h2dQM6.jpg" alt="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图" width="535" height="302" /></figure>
<p>然生重载 Nginx 配置完成！</p>
<figure class="wp-block-image size-full"><img decoding="async" class="lazy entered loaded alignnone size-full wp-image-3402" title="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图1" src="https://i.p1e.cn/2023/03/blog202303221716213L7Sey.png" alt="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图1" width="1010" height="833" /></figure>
<p>测试访问网站后，查看日志，已显示真实IP，就是这么简单！</p>
<figure class="wp-block-image size-full"><img decoding="async" class="lazy entered loaded alignnone size-full wp-image-3403" title="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图2" src="https://i.p1e.cn/2023/03/blog20230322171624ZGTLUs.png" alt="Nginx服务器接入百度云加速CDN后如何获取真实访客IP？插图2" width="821" height="363" /></figure>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3400.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>nginx反向代理时上传卡死或速度慢的解决办法</title>
		<link>https://p1e.cn/html/3396.html</link>
					<comments>https://p1e.cn/html/3396.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Tue, 14 Mar 2023 04:27:39 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[反代]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3396</guid>

					<description><![CDATA[1.打开宝塔控制面板，选择“网站”，选择左侧“反向代理”，点击“配置文件”。 2.在location{}内添加箭头所指的一行代码：client_max_body_size 1024m;]]></description>
										<content:encoded><![CDATA[<p>1.打开宝塔控制面板，选择“网站”，选择左侧“反向代理”，点击“配置文件”。</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3397" src="https://i.p1e.cn/2023/03/blog202303141225052023031404250593.png" alt="" width="944" height="695" /></p>
<p>2.在location{}内添加箭头所指的一行代码：<code>client_max_body_size 1024m;</code></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3398" src="https://i.p1e.cn/2023/03/blog202303141227152023031404271530.png" alt="" width="657" height="479" /></p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3396.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>几个常用 Nginx 规则</title>
		<link>https://p1e.cn/html/3271.html</link>
					<comments>https://p1e.cn/html/3271.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Sun, 29 Jan 2023 03:01:56 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3271</guid>

					<description><![CDATA[本人常用的几个 Nginx 规则，笔记笔记。 防止tpl inc cfg文件被下载 location ~* \.(tpl&#124;inc&#124;cfg)$ { deny all; } 套用CDN的情况返回真实IP add_header X-Real-IP $http_x_real_ip; set_real_ip_from 0.0.0.0/0; real_ip_header X-Real-IP; real_ip_recursive on; SSL反代 server { listen 443; server_name www.cca]]></description>
										<content:encoded><![CDATA[<p>本人常用的几个 Nginx 规则，笔记笔记。<br />
防止tpl inc cfg文件被下载</p>
<pre>location ~* \.(tpl|inc|cfg)$ { 
        deny all;
        }
</pre>
<p>套用CDN的情况返回真实IP</p>
<pre>add_header X-Real-IP $http_x_real_ip;
        set_real_ip_from 0.0.0.0/0;
        real_ip_header X-Real-IP;
        real_ip_recursive on;
</pre>
<p>SSL反代</p>
<pre>server
    {
     listen 443;
      server_name www.ccav.me ccav.me;
      #rewrite ^/(.*) https://$server_name$1 permanent;
      ssl on;
      ssl_certificate /root/#PEM/CRT;
      ssl_certificate_key /root/#KEY;
      #               ssl_protocols SSLv2 SSLv3 TLSv1;
       #              ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        #             ssl_prefer_server_ciphers on;
     #listen 80;
      location / {
      proxy_redirect www.B.com /;
      proxy_pass https://www.B.com;
      proxy_set_header Accept-Encoding "";
      proxy_set_header User-Agent $http_user_agent;
      proxy_set_header Accept-Language "zh-CN";
      proxy_set_header X-Real-IP $remote_addr;

    }
    }
 
server
    {
     listen 80;
      server_name www.815494.com 815494.com;
      rewrite ^(.*) https://$server_name$1 permanent;
    }
</pre>
<p>根据指定来访IP跳转</p>
<pre>if ($remote_addr ~* "192.168.1.2|192.168.1.3|103.118.40.232192.168.1.4") {
rewrite ^/(.*) https://815494.com;
}
</pre>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3271.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>宝塔面板开启SSL强制跳转后实现指定目录不跳转HTTPS</title>
		<link>https://p1e.cn/html/3162.html</link>
					<comments>https://p1e.cn/html/3162.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Thu, 27 Jan 2022 01:00:01 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[宝塔]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3162</guid>

					<description><![CDATA[虽然使用加密连接https更加安全，但在一些特定情况下却只能使用http不能使用加密连接； 在宝塔面板中开启SSL强制跳转后全站所有目录都会跳转到https并没有例外的选项； 本来以为加一条if指定条件不跳转就行了，结果不能实现，原来Nginx不支持if逻辑和嵌套语法； 最后找了不少资料，终于可以实现开启强制跳转后指定目录不跳转https的方案了； 方案 宝塔面板开启强制跳转https后Nginx的配置文件是如下代码； if ($server_port !~ 443){ rewrite ^(/.*)$ https:]]></description>
										<content:encoded><![CDATA[<p>虽然使用加密连接https更加安全，但在一些特定情况下却只能使用http不能使用加密连接；<br />
在宝塔面板中开启SSL强制跳转后全站所有目录都会跳转到https并没有例外的选项；<br />
本来以为加一条if指定条件不跳转就行了，结果不能实现，原来Nginx不支持if逻辑和嵌套语法；<br />
最后找了不少资料，终于可以实现开启强制跳转后指定目录不跳转https的方案了；</p>
<div data-unique="方案"></div>
<h2>方案</h2>
<p>宝塔面板开启强制跳转https后Nginx的配置文件是如下代码；</p>
<pre>
if ($server_port !~ 443){
   rewrite ^(/.*)$ https://$host$1 permanent;
    }
</pre>
<p>然后我们在网站-设置-配置文件中用以下代码替换掉上面的代码即可；</p>
<pre>
    set $flag 0;
    if ($server_port !~ 443) {
        set $flag "${flag}1";
    }
    if ($request_uri !~ "/AAA"){
        set $flag "${flag}2";
    }
    if ($flag = "012"){
         rewrite ^(.*)$  https://$host$1 permanent;
    }
</pre>
<p>条件解释：满足非443端口并且域名目录非/AAA时跳转，包含/AAA目录不跳转；</p>
<div data-unique="说明"></div>
<h2>说明</h2>
<p>我们指定不跳转的目录是/AAA但如果有同名目录，比如/AAAA同样也不会跳转；</p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3162.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>宝塔面板下nginx屏蔽垃圾蜘蛛禁止抓取不影响火车头发布</title>
		<link>https://p1e.cn/html/3112.html</link>
					<comments>https://p1e.cn/html/3112.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Sun, 16 Jan 2022 06:23:57 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[宝塔]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3112</guid>

					<description><![CDATA[最近查看服务器日志，发现一些垃圾蜘蛛，一直爬行很多，比如以下这些垃圾，太烦人了。 Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)" Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)" 本人一直使用的linux系统服务器宝塔面板管理，个人感觉比较方便。网上查找方法，屏蔽这些垃圾。 网上找到的代码如下：目前为止比较好用。 #禁止Scr]]></description>
										<content:encoded><![CDATA[<p>最近查看服务器日志，发现一些垃圾蜘蛛，一直爬行很多，比如以下这些垃圾，太烦人了。</p>
<pre>Mozilla/5.0 (compatible; SemrushBot/6~bl; +http://www.semrush.com/bot.html)"
Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)"</pre>
<p>本人一直使用的linux系统服务器宝塔面板管理，个人感觉比较方便。网上查找方法，屏蔽这些垃圾。</p>
<p>网上找到的代码如下：目前为止比较好用。</p>
<pre>#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}
#禁止指定UA及UA为空的访问
if ($http_user_agent ~* "FeedDemon|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|Bytespider|Ezooms|Googlebot|JikeSpider|SemrushBot|^$" ) {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}</pre>
<p>宝塔面板下使用方法如下：<br />
1、找到文件目录/www/server/nginx/conf文件夹下面，新建一个文件<br />
<code>agent_deny.conf</code><br />
内容就是以上代码。<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-3115" src="//i.p1e.cn/2022/01/1642314600-20200323230338216.png" alt="" width="855" height="531" /><br />
2.找到网站设置里面的第7行左右 写入代码： include agent_deny.conf;<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-3116" src="//i.p1e.cn/2022/01/1642314702-16423147241.png" alt="" width="962" height="599" /><br />
如果你网站使用火车头采集发布，使用以上代码会返回403错误，发布不了的。如果想使用火车头采集发布，请使用下面的代码</p>
<pre>#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}
#禁止指定UA访问。UA为空的可以访问，比如火车头可以正常发布。
if  ($http_user_agent ~ "FeedDemon|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|YandexBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|Bytespider|Ezooms|Googlebot|JikeSpider|SemrushBot" ) {
return 403;             
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
</pre>
<p>最后重启重启nginx，就可以在网站日志里看到防御效果了。<img loading="lazy" decoding="async" class="alignnone size-full wp-image-3117" src="//i.p1e.cn/2022/01/1642314950-16423149411.png" alt="" width="714" height="728" /></p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3112.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>宝塔面板开启Nginx fastcgi_cache缓存为WordPress提速</title>
		<link>https://p1e.cn/html/3099.html</link>
					<comments>https://p1e.cn/html/3099.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Wed, 12 Jan 2022 05:11:39 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3099</guid>

					<description><![CDATA[说到wordpress的缓存，大家想到的肯定是 WP-Super-Cache 的静态html缓存，以及 memcached 或 redis 动态缓存，插件的缓存效果肯定是有的，但是容易出现各种问题，比如配置很复杂、配置全英文、插件之间的冲突等，所以今天我要教大家一个更高级的缓存：Nginx fastcgi_cache缓存，直接在nginx层面缓存页面，还支持缓存伪静态！效果比起传统的php缓存好得太多了，因为很多人使用宝塔面板，所以今天的教程是基于宝塔面板的教程。 全局设置 现在我们开始配置nginx，来到宝塔后台]]></description>
										<content:encoded><![CDATA[<p>说到wordpress的缓存，大家想到的肯定是 <strong>WP-Super-Cache</strong> 的静态html缓存，以及 <strong>memcached</strong> 或 <strong>redis</strong> 动态缓存，插件的缓存效果肯定是有的，但是容易出现各种问题，比如配置很复杂、配置全英文、插件之间的冲突等，所以今天我要教大家一个更高级的缓存：<strong>Nginx fastcgi_cache缓存</strong>，直接在nginx层面缓存页面，还支持缓存伪静态！效果比起传统的php缓存好得太多了，因为很多人使用宝塔面板，所以今天的教程是基于宝塔面板的教程。</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><a href="https://i.p1e.cn/2022/01/blog20220127010556l5wi5b.png" rel="lightbox[pic]"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3163" src="https://i.p1e.cn/2022/01/blog20220127010556l5wi5b.png" width="680" height="416" /></a></figure>
<h2>全局设置</h2>
<p>现在我们开始配置nginx，来到宝塔后台，在软件商店找到Nginx，点击设置按钮，在配置修改中添加以下内容：</p>
<pre class="wp-block-code"><code>fastcgi_cache_path /tmp/wpcache levels=1:2 keys_zone=WORDPRESS:250m inactive=1d max_size=1G;
fastcgi_temp_path /tmp/wpcache/temp;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
#忽略一切 nocache 申明，避免不缓存伪静态等
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;</code></pre>
<p>加好之后截图如下：</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3103" src="//i.p1e.cn/2022/01/k5sUeU.png" width="650" height="602" /><figcaption>添加全局缓存设置</figcaption></figure>
</div>
<h2>网站设置</h2>
<p>在宝塔后台的网站列表中，找到你的网站，并且点击设置按钮，将以下代码添加到配置文件中去：</p>
<pre class="wp-block-code"><code>set $skip_cache 0;
#post 访问不缓存
if ($request_method = POST) {
	set $skip_cache 1;
}   
#动态查询不缓存
if ($query_string != "") {
	set $skip_cache 1;
}   
#后台等特定页面不缓存（其他需求请自行添加即可）
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
	set $skip_cache 1;
}   
#对登录用户、评论过的用户不展示缓存
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
	set $skip_cache 1;
}
#这里请参考你网站之前的配置，特别是sock的路径，弄错了就502了！如果你的网站使用PHP7.4，就写-74.sock
location ~ [^/]\.php(/|$)
{
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php-cgi-74.sock;
    fastcgi_index index.php;
    include fastcgi.conf;  
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
    #新增的缓存规则
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    add_header X-Cache "$upstream_cache_status From $host";
    fastcgi_cache WORDPRESS;
    add_header Cache-Control  max-age=0;
    add_header Nginx-Cache "$upstream_cache_status";
    add_header Last-Modified $date_gmt;
    add_header X-Frame-Options SAMEORIGIN; # 只允许本站用 frame 来嵌套
    add_header X-Content-Type-Options nosniff; # 禁止嗅探文件类型
    add_header X-XSS-Protection "1; mode=block"; # XSS 保护
    etag  on;
    fastcgi_cache_valid 200 301 302 1d;
}
#缓存清理配置
location ~ /purge(/.*) {
	allow 127.0.0.1;
	allow "服务器外网IP"; # 引号要保留
	deny all;
	fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}</code></pre>
<p>加好之后的截图如下：</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><figcaption><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3101" src="//i.p1e.cn/2022/01/1641964211-16419626861.png" alt="" width="776" height="546" /><br />
局部站点设置</figcaption></figure>
</div>
<p>添加好之后，重载Nginx设置，缓存就加好了，</p>
<p>按 <strong>F12</strong> 开启开发者工具，在未登录的情况下访问网站首页，查看文件头，如果出现 <strong>HIT</strong> 则是缓存了，<strong>BYPASS</strong> 则是因设置原因未缓存，<strong>MISS</strong> 即这个页面还没被缓存，新发布或刚被删除的页面，首次访问将出现这个状态，如图所示：</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><figcaption><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3102" src="//i.p1e.cn/2022/01/1641964243-16419634931.png" alt="" width="585" height="451" /><br />
缓存命中！</figcaption></figure>
</div>
</div>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3099.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>BT宝塔面板修改nginx默认80端口为任意端口</title>
		<link>https://p1e.cn/html/3076.html</link>
					<comments>https://p1e.cn/html/3076.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Thu, 16 Dec 2021 07:16:31 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[宝塔]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=3076</guid>

					<description><![CDATA[有时我们需要使用80端口，可nginx的默认端口为80 故需要将nginx默认端口80为其他任意端口 nginx的配置文件路径： www/server/panel/vhost/nginx/ 把这个目录里面的conf配置文件的80全部改成你要的端口，我这里是改成81 其次，每增加一个站点，会增加一个此站点的配置文件，所以后期增加站点后也要来这里修改下端口。因为增加的端口默认是80。 配置文件修改完毕后需要重启下nginx。然后在安全里面放行你更改后的端口。]]></description>
										<content:encoded><![CDATA[<p><strong>有时我们需要使用80端口，可nginx的默认端口为80<br />
故需要将nginx默认端口80为其他任意端口</strong></p>
<h3 id="toc-head-0">nginx的配置文件路径：</h3>
<p>www/server/panel/vhost/nginx/<br />
<img loading="lazy" decoding="async" class="gallery-img alignnone size-full wp-image-3077" src="https://i.p1e.cn/2021/12/UmBf9o.png" alt="image.png" width="858" height="335" /><br />
<strong>把这个目录里面的conf配置文件的80全部改成你要的端口，我这里是改成81</strong></p>
<p>其次，每增加一个站点，会增加一个此站点的配置文件，所以后期增加站点后也要来这里修改下端口。因为增加的端口默认是80。</p>
<p><img loading="lazy" decoding="async" class="gallery-img alignnone size-full wp-image-3078" src="https://i.p1e.cn/2021/12/wr2sS6.png" alt="image.png" width="1169" height="250" /><br />
<img loading="lazy" decoding="async" class="gallery-img alignnone size-full wp-image-3079" src="https://i.p1e.cn/2021/12/HrhL7W.png" alt="image.png" width="573" height="529" /><br />
配置文件修改完毕后需要重启下nginx。然后在安全里面放行你更改后的端口。</p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/3076.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>nginx 反向代理 502 错误的解决</title>
		<link>https://p1e.cn/html/2939.html</link>
					<comments>https://p1e.cn/html/2939.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Tue, 04 May 2021 05:18:45 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[502]]></category>
		<category><![CDATA[nginx]]></category>
		<guid isPermaLink="false">https://www.815494.com/?p=2939</guid>

					<description><![CDATA[Nginx反向代理&#8212;-502报错 问题描述：通过nginx反向代理地址之后报错502，后台日志报错信息为（upstream sent too big header while reading response header from upstream） 问题原因：nginx中proxy_buffer_size默认值是4k，第三方地址响应头超过了此长度，Nginx报upstream sent too big header错误，然后client收到的是502。 解决方案：在http字段中增加以下三个参数 p]]></description>
										<content:encoded><![CDATA[<p>Nginx反向代理&#8212;-502报错<br />
问题描述：通过nginx反向代理地址之后报错502，后台日志报错信息为（upstream sent too big header while reading response header from upstream）<br />
问题原因：nginx中proxy_buffer_size默认值是4k，第三方地址响应头超过了此长度，Nginx报upstream sent too big header错误，然后client收到的是502。<br />
解决方案：在http字段中增加以下三个参数<br />
proxy_buffer_size 128k;<br />
作用：Nginx使用该大小申请read_buf（读取数组长度），即大小指定了 upstream header 最大长度，如果响应头超过了这个长度，Nginx会报upstream sent too big header错误，然后client收到的是502。<br />
proxy_buffers   32 32k;<br />
作用：设置存储被代理服务器响应的body所占用的buffer个数和每个buffer大小。<br />
#   proxy_busy_buffers_size 64k;<br />
作用：proxy_busy_buffers_size不是独立的空间，他是proxy_buffers和proxy_buffer_size的一部分。<br />
nginx会在没有完全读完后端响应就开始向客户端传送数据，所以它会划出一部分busy状态的buffer来专门向客户端传送数据(建议为proxy_buffers中单个缓冲区的2倍)，然后它继续从后端取数据。<br />
proxy_busy_buffer_size参数用来设置处于busy状态的buffer有多大。</p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/2939.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>nginx下301跳转到https出现不安全连接的问题</title>
		<link>https://p1e.cn/html/976.html</link>
					<comments>https://p1e.cn/html/976.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Mon, 29 Apr 2019 07:27:27 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[nginx]]></category>
		<guid isPermaLink="false">http://www.815494.com/html/976.html</guid>

					<description><![CDATA[群里小伙伴上次变更域名后，将老域名通过301跳转到新域名(参看：宝塔面板操作多个域名做301跳转)后，落下了一个后遗症：开启强制SSL后，通过输入老域名或者外部链接到老域名，会出现301不生效，浏览器加载一个您的链接不是私密连接的对话页面。这就尴尬了，既要保证正常跳转，又需要强制SSL连接，通过重新配置nginx的301跳转来改造下。 先上一张图，就是上面提到的不是私密连接 正题，配置方法（以宝塔面板为例）。 第一步删除上次的老域名的301跳转代码 注意server_name中只保留新域名的主域和www二级，然后删]]></description>
										<content:encoded><![CDATA[<p>群里小伙伴上次变更域名后，将老域名通过301跳转到新域名(参看：<a style="color: #19a97b; background-color: transparent;" href="https://p1e.cn/html/955.html" target="_blank" rel="noopener noreferrer">宝塔面板操作多个域名做301跳转</a>)后，落下了一个后遗症：开启强制SSL后，通过输入老域名或者外部链接到老域名，会出现301不生效，浏览器加载一个您的链接不是私密连接的对话页面。这就尴尬了，既要保证正常跳转，又需要强制SSL连接，通过重新配置nginx的301跳转来改造下。</p>
<p>先上一张图，就是上面提到的不是私密连接</p>
<p class="ql-align-center"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-977" src="https://i.p1e.cn/2019/04/oQL8m9.jpg" alt="1.jpg" width="725" height="407" /></p>
<p>正题，配置方法（以宝塔面板为例）。</p>
<h4><strong>第一步删除上次的老域名的301跳转代码</strong></h4>
<p>注意server_name中只保留新域名的主域和www二级，然后删除下发的301跳转。</p>
<h4><strong>第二步复制整个server，粘贴到下面</strong></h4>
<p>1、server_name中写老域名（如本测试的数据ce.anji.net）</p>
<p>2、删除整段强制SSL</p>
<p>3、添加上301跳转内容</p>
<p class="ql-align-center"><img loading="lazy" decoding="async" class="alignnone size-full ql-align-center wp-image-978" src="https://i.p1e.cn/2019/04/llHIp5.jpg" alt="2.jpg" width="664" height="612" /></p>
<p class="ql-align-center"><img loading="lazy" decoding="async" class="alignnone size-full ql-align-center wp-image-979" src="https://i.p1e.cn/2019/04/SUTZYd.jpg" alt="3.jpg" width="672" height="613" /></p>
<p>全部完成后，保存，清除浏览器缓存后再试试看吧，通常能即刻生效，如果无效果，尝试重启下nginx即可。</p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/976.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Nginx常用屏蔽规则，让网站更安全</title>
		<link>https://p1e.cn/html/579.html</link>
					<comments>https://p1e.cn/html/579.html#respond</comments>
		
		<dc:creator><![CDATA[Naoki]]></dc:creator>
		<pubDate>Mon, 15 Oct 2018 02:06:07 +0000</pubDate>
				<category><![CDATA[运维笔记]]></category>
		<category><![CDATA[nginx]]></category>
		<guid isPermaLink="false">http://www.815494.com/?p=579</guid>

					<description><![CDATA[在开始之前，希望您已经熟悉Nginx常用命令（如停止、重启等操作）及排查nginx错误日志，以免出现问题不知所措。如无特殊注明，以下的命令均添加到server段内，修改nginx配置之前务必做好备份，修改完毕后需要重载一次nginx，否则不会生效。 防止文件被下载 比如将网站数据库导出到站点根目录进行备份，很有可能也会被别人下载，从而导致数据丢失的风险。以下规则可以防止一些常规的文件被下载，可根据实际情况增减。 location ~ .(zip&#124;rar&#124;sql&#124;bak&#124;gz&#124;7z)$ { return 444; }]]></description>
										<content:encoded><![CDATA[<p>在开始之前，希望您已经熟悉Nginx常用命令（如停止、重启等操作）及排查nginx错误日志，以免出现问题不知所措。如无特殊注明，以下的命令均添加到<code>server</code>段内，<strong>修改nginx配置之前务必做好备份，修改完毕后需要重载一次nginx，否则不会生效。</strong></p>
<h3>防止文件被下载</h3>
<p>比如将网站数据库导出到站点根目录进行备份，很有可能也会被别人下载，从而导致数据丢失的风险。以下规则可以防止一些常规的文件被下载，可根据实际情况增减。</p>
<pre><code class="language-nginx hljs"><span class="hljs-attribute">location</span> <span class="hljs-regexp">~ .(zip|rar|sql|bak|gz|7z)$</span> {
  <span class="hljs-attribute">return</span> <span class="hljs-number">444</span>;
}</code></pre>
<h3>屏蔽非常见蜘蛛（爬虫）</h3>
<p>如果经常分析网站日志你会发现，一些奇怪的UA总是频繁的来访问网站，而这些UA对网站收录毫无意义，反而增加服务器压力，可以直接将其屏蔽。</p>
<pre><code class="language-nginx hljs"><span class="hljs-attribute">if</span> (<span class="hljs-variable">$http_user_agent</span> <span class="hljs-regexp">~* (SemrushBot|python|MJ12bot|AhrefsBot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup))</span> {
     <span class="hljs-attribute">return</span> <span class="hljs-number">444</span>;
}</code></pre>
<h3>禁止某个目录执行脚本</h3>
<p>比如网站上传目录，通常存放的都是静态文件，如果因程序验证不严谨被上传木马程序，导致网站被黑。以下规则请根据自身情况改为您自己的目录，需要禁止的脚本后缀也可以自行添加。</p>
<pre><code class="language-nginx hljs"><span class="hljs-comment">#uploads|templets|data 这些目录禁止执行PHP</span>
<span class="hljs-attribute">location</span> <span class="hljs-regexp">~* ^/(uploads|templets|data)/.*.(php|php5)$</span> {
    <span class="hljs-attribute">return</span> <span class="hljs-number">444</span>;
}</code></pre>
<h3>屏蔽某个IP或IP段</h3>
<p>如果网站被恶意灌水或CC攻击，可从网站日志中分析特征IP，将其IP或IP段进行屏蔽。</p>
<pre><code class="language-nginx hljs"><span class="hljs-comment">#屏蔽192.168.5.23这个IP</span>
<span class="hljs-attribute">deny</span> <span class="hljs-number">192.168.5.23</span>;
<span class="hljs-comment">#屏蔽192.168.5.* 这个段</span>
<span class="hljs-attribute">denu</span> <span class="hljs-number">192.168.5.0</span>/<span class="hljs-number">24</span>;</code></pre>
<h3>其它说明</h3>
<p>再次强调，<strong>修改nginx配置之前务必做好备份，修改完毕后需要重载一次nginx，否则不会生效。</strong></p>
<p>上面大部分规则返回<code>444</code>状态码而不是<code>403</code>，因为444状态码在nginx中有特殊含义。nginx的444状态是直接由服务器中断连接，不会向客户端再返回任何消息，比返回403更加暴力。若有不足还请补充和指正。</p>
<div></div>]]></content:encoded>
					
					<wfw:commentRss>https://p1e.cn/html/579.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
